Commit 141b26f6 authored by Lukas 'Eipi' Eipert's avatar Lukas 'Eipi' Eipert

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
parent 90b68e06
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment