summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hegyi <ahegyi@gitlab.com>2019-06-19 07:48:19 +0200
committerAdam Hegyi <ahegyi@gitlab.com>2019-06-24 21:02:33 +0200
commit9a831e4824b6f986801533c34574b46c6b2cbcaf (patch)
tree90d14ebd2398419839f71900e0aa4ad155dff40a
parenta949cc3518bc97997cebbb586eddf98270126262 (diff)
downloadgitlab-ce-63406-fix-copying-a-single-line-from-firefox.tar.gz
Fix copying a single line from Firefox63406-fix-copying-a-single-line-from-firefox
This change ensures that all open <span> tags are closed before adding a <br> tag. The <br> tag is also wrapped with its own <span>.
-rw-r--r--lib/gitlab/ci/ansi2html.rb21
-rw-r--r--spec/lib/gitlab/ci/ansi2html_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/trace/stream_spec.rb10
-rw-r--r--spec/support/shared_examples/ci_trace_shared_examples.rb2
4 files changed, 28 insertions, 13 deletions
diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb
index fc3223e7442..2f7448396d2 100644
--- a/lib/gitlab/ci/ansi2html.rb
+++ b/lib/gitlab/ci/ansi2html.rb
@@ -196,11 +196,18 @@ module Gitlab
def handle_new_line
css_classes = []
+ css_classes_for_br = []
+
if @sections.any?
css_classes = %w[section line] + sections.map { |section| "s_#{section}" }
end
- write_in_tag %{<br/>}
+ # Section classes should not apply to the first newline, so it stays visible after closing a section
+ unless beginning_of_section?
+ css_classes_for_br = section_classes(sections)
+ end
+
+ write_raw %{<span class="#{css_classes_for_br.join(' ')}"><br/></span>}
write_raw %{<span class="#{css_classes.join(' ')}"></span>} if css_classes.any?
@lineno_in_section += 1
open_new_tag
@@ -310,14 +317,18 @@ module Gitlab
if @sections.any?
css_classes << "section"
- css_classes << "js-section-header section-header" if @lineno_in_section == 0
- css_classes += sections.map { |section| "js-s-#{section}" }
+ css_classes << "js-section-header section-header" if beginning_of_section?
+ css_classes += section_classes(sections)
end
@out << %{<span class="#{css_classes.join(' ')}">}
@n_open_tags += 1
end
+ def beginning_of_section?
+ @lineno_in_section == 0
+ end
+
def close_open_tags
while @n_open_tags > 0
@out << %{</span>}
@@ -374,6 +385,10 @@ module Gitlab
@bg_color = get_term_color_class(color_index, ["bg", prefix])
end
+ def section_classes(sections)
+ sections.map { |section| "js-s-#{section}" }
+ end
+
def get_term_color_class(color_index, prefix)
color_name = COLOR[color_index]
return if color_name.nil?
diff --git a/spec/lib/gitlab/ci/ansi2html_spec.rb b/spec/lib/gitlab/ci/ansi2html_spec.rb
index 3d57ce431ab..2dca3546c35 100644
--- a/spec/lib/gitlab/ci/ansi2html_spec.rb
+++ b/spec/lib/gitlab/ci/ansi2html_spec.rb
@@ -141,11 +141,11 @@ describe Gitlab::Ci::Ansi2html do
end
it "replaces newlines with line break tags" do
- expect(convert_html("\n")).to eq('<span class=""><br/><span class=""></span></span>')
+ expect(convert_html("\n")).to eq('<span class=""><br/></span><span class=""></span>')
end
it "groups carriage returns with newlines" do
- expect(convert_html("\r\n")).to eq('<span class=""><br/><span class=""></span></span>')
+ expect(convert_html("\r\n")).to eq('<span class=""><br/></span><span class=""></span>')
end
describe "incremental update" do
@@ -193,7 +193,7 @@ describe Gitlab::Ci::Ansi2html do
let(:pre_text) { "Hello\r" }
let(:pre_html) { "<span class=\"\">Hello\r</span>" }
let(:text) { "\nWorld" }
- let(:html) { "<span class=\"\"><br/><span class=\"\">World</span></span>" }
+ let(:html) { "<span class=\"\"><br/></span><span class=\"\">World</span>" }
it_behaves_like 'stateable converter'
end
@@ -232,7 +232,7 @@ describe Gitlab::Ci::Ansi2html do
it 'prints light red' do
text = "#{section_start}\e[91mHello\e[0m\n#{section_end}"
header = %{<span class="term-fg-l-red section js-section-header section-header js-s-#{class_name(section_name)}">Hello</span>}
- line_break = %{<span class="section js-section-header section-header js-s-#{class_name(section_name)}"><br/></span>}
+ line_break = %{<span class=""><br/></span>}
line = %{<span class="section line s_#{class_name(section_name)}"></span>}
empty_line = %{<span class="section js-s-#{class_name(section_name)}"></span>}
html = "#{section_start_html}#{header}#{line_break}#{line}#{empty_line}#{section_end_html}"
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index 35250632e86..f2f88841dbd 100644
--- a/spec/lib/gitlab/ci/trace/stream_spec.rb
+++ b/spec/lib/gitlab/ci/trace/stream_spec.rb
@@ -65,9 +65,9 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
result = stream.html
expect(result).to eq(
- "<span class=\"\">ヾ(´༎ຶД༎ຶ`)ノ<br/><span class=\"\"></span></span>"\
- "<span class=\"term-fg-green\">許功蓋</span><span class=\"\"><br/>"\
- "<span class=\"\"></span></span>")
+ "<span class=\"\">ヾ(´༎ຶД༎ຶ`)ノ</span><span class=\"\"><br/></span><span class=\"\"></span>"\
+ "<span class=\"term-fg-green\">許功蓋</span><span class=\"\"><br/></span>"\
+ "<span class=\"\"></span>")
expect(result.encoding).to eq(Encoding.default_external)
end
end
@@ -306,8 +306,8 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
shared_examples_for 'htmls' do
it "returns html" do
expect(stream.html).to eq(
- "<span class=\"\">12<br/><span class=\"\">34<br/>"\
- "<span class=\"\">56</span></span></span>")
+ "<span class=\"\">12</span><span class=\"\"><br/></span><span class=\"\">34</span><span class=\"\"><br/></span>"\
+ "<span class=\"\">56</span>")
end
it "returns html for last line only" do
diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb
index f985b2dcbba..44e0209ef64 100644
--- a/spec/support/shared_examples/ci_trace_shared_examples.rb
+++ b/spec/support/shared_examples/ci_trace_shared_examples.rb
@@ -5,7 +5,7 @@ shared_examples_for 'common trace features' do
end
it "returns formatted html" do
- expect(trace.html).to eq("<span class=\"\">12<br/><span class=\"\">34</span></span>")
+ expect(trace.html).to eq("<span class=\"\">12</span><span class=\"\"><br/></span><span class=\"\">34</span>")
end
it "returns last line of formatted html" do