diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-04-13 21:31:32 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-04-13 21:31:32 +0800 |
commit | 61ca398ff8968ee59ba0ac0645f64ef4ce6dbbf9 (patch) | |
tree | 1a0bfb005a7e33485a0e589a6b83da456049b269 | |
parent | 92e15623e55e0cbe877969d57798e40da6231850 (diff) | |
download | gitlab-ce-fix-trace-seeking.tar.gz |
Only enforce the first line because that's wherefix-trace-seeking
the data could be corrupted.
-rw-r--r-- | lib/ci/ansi2html.rb | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/ci/ansi2html.rb b/lib/ci/ansi2html.rb index aab07c31076..f8be7d01049 100644 --- a/lib/ci/ansi2html.rb +++ b/lib/ci/ansi2html.rb @@ -151,23 +151,12 @@ module Ci open_new_tag - stream.each_line do |line| - s = StringScanner.new(enforce_utf8(line)) - until s.eos? - if s.scan(/\e([@-_])(.*?)([@-~])/) - handle_sequence(s) - elsif s.scan(/\e(([@-_])(.*?)?)?$/) - break - elsif s.scan(/</) - @out << '<' - elsif s.scan(/\r?\n/) - @out << '<br>' - else - @out << s.scan(/./m) - end - @offset += s.matched_size - end - end + # The first line could be corrupted because we might cut it + # in the middle, so we need to make sure the first line is ok. + first_line = stream.readline + scan_one_line(enforce_utf8(first_line)) + + stream.each_line(&method(:scan_one_line)) close_open_tags() @@ -329,6 +318,24 @@ module Ci private + def scan_one_line(line) + s = StringScanner.new(line) + until s.eos? + if s.scan(/\e([@-_])(.*?)([@-~])/) + handle_sequence(s) + elsif s.scan(/\e(([@-_])(.*?)?)?$/) + break + elsif s.scan(/</) + @out << '<' + elsif s.scan(/\r?\n/) + @out << '<br>' + else + @out << s.scan(/./m) + end + @offset += s.matched_size + end + end + def enforce_utf8(bytes) bytes.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') end |