summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Eipert <leipert@gitlab.com>2019-07-30 03:18:13 +0200
committerLukas Eipert <leipert@gitlab.com>2019-07-30 17:56:58 +0200
commit5366c89bd62d6305f71566c9ebd0573b3027a349 (patch)
tree9722c6db43b6522c91e450504abab28ca1826a4a
parent6b45d85e65c2e794e28f7b5afb372b94fc44bbe1 (diff)
downloadgitlab-ce-5366c89bd62d6305f71566c9ebd0573b3027a349.tar.gz
Fix deep DOM tree problem in ansi2html
Currently the ansi2html color library will create growing DOM trees under the following condition: 1. If the log has no sections, e.g. when it is too long and truncated 2. A lot of consecutive log items have the same color
-rw-r--r--lib/gitlab/ci/ansi2html.rb7
-rw-r--r--spec/lib/gitlab/ci/ansi2html_spec.rb6
-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, 11 insertions, 14 deletions
diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb
index 7a7679a1f6b..8335e1c1a7a 100644
--- a/lib/gitlab/ci/ansi2html.rb
+++ b/lib/gitlab/ci/ansi2html.rb
@@ -194,16 +194,15 @@ module Gitlab
end
def handle_new_line
- css_classes = []
+ write_in_tag %{<br/>}
if @sections.any?
css_classes = %w[section line] + sections.map { |section| "s_#{section}" }
+ write_raw %{<span class="#{css_classes.join(' ')}"></span>}
end
- write_in_tag %{<br/>}
- write_raw %{<span class="#{css_classes.join(' ')}"></span>} if css_classes.any?
@lineno_in_section += 1
- open_new_tag
+ ensure_open_new_tag
end
def handle_section(scanner)
diff --git a/spec/lib/gitlab/ci/ansi2html_spec.rb b/spec/lib/gitlab/ci/ansi2html_spec.rb
index 960c9aa9b83..4881ef15eab 100644
--- a/spec/lib/gitlab/ci/ansi2html_spec.rb
+++ b/spec/lib/gitlab/ci/ansi2html_spec.rb
@@ -143,11 +143,11 @@ describe Gitlab::Ci::Ansi2html do
end
it "replaces newlines with line break tags" do
- expect(convert_html("\n")).to eq('<span><br/><span></span></span>')
+ expect(convert_html("\n")).to eq('<span><br/></span>')
end
it "groups carriage returns with newlines" do
- expect(convert_html("\r\n")).to eq('<span><br/><span></span></span>')
+ expect(convert_html("\r\n")).to eq('<span><br/></span>')
end
describe "incremental update" do
@@ -195,7 +195,7 @@ describe Gitlab::Ci::Ansi2html do
let(:pre_text) { "Hello\r" }
let(:pre_html) { "<span>Hello\r</span>" }
let(:text) { "\nWorld" }
- let(:html) { "<span><br/><span>World</span></span>" }
+ let(:html) { "<span><br/>World</span>" }
it_behaves_like 'stateable converter'
end
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index 033bb83d1c3..af519f4bae6 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>ヾ(´༎ຶД༎ຶ`)ノ<br/><span></span></span>"\
- "<span class=\"term-fg-green\">許功蓋</span><span><br/>"\
- "<span></span></span>")
+ "<span>ヾ(´༎ຶД༎ຶ`)ノ<br/></span>"\
+ "<span class=\"term-fg-green\">許功蓋</span>"\
+ "<span><br/></span>")
expect(result.encoding).to eq(Encoding.default_external)
end
end
@@ -305,9 +305,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
describe '#html' do
shared_examples_for 'htmls' do
it "returns html" do
- expect(stream.html).to eq(
- "<span>12<br/><span>34<br/>"\
- "<span>56</span></span></span>")
+ expect(stream.html).to eq("<span>12<br/>34<br/>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 f221b6afdec..e2b4b50d41d 100644
--- a/spec/support/shared_examples/ci_trace_shared_examples.rb
+++ b/spec/support/shared_examples/ci_trace_shared_examples.rb
@@ -7,7 +7,7 @@ shared_examples_for 'common trace features' do
end
it "returns formatted html" do
- expect(trace.html).to eq("<span>12<br/><span>34</span></span>")
+ expect(trace.html).to eq("<span>12<br/>34</span>")
end
it "returns last line of formatted html" do