diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-13 16:58:09 +0000 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-04-13 14:38:36 -0300 |
commit | c1c0e9e0843ab7076f0d981fb63ce8dac2968066 (patch) | |
tree | 1acc703f05f2dd7a38aafd69c327b21c70c09901 | |
parent | 03dfbe241a3e73bba1b118edca1a3f838683c64a (diff) | |
download | gitlab-ce-c1c0e9e0843ab7076f0d981fb63ce8dac2968066.tar.gz |
Merge branch 'fix-trace-seeking-readline' into 'master'
After Trace#limit, we seek to the next line in case
Closes #30796
See merge request !10681
-rw-r--r-- | changelogs/unreleased/fix-trace-seeking.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/trace/stream.rb | 7 | ||||
-rw-r--r-- | spec/fixtures/trace/ansi-sequence-and-unicode | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/trace/stream_spec.rb | 28 | ||||
-rw-r--r-- | spec/support/fixture_helpers.rb | 7 |
5 files changed, 41 insertions, 10 deletions
diff --git a/changelogs/unreleased/fix-trace-seeking.yml b/changelogs/unreleased/fix-trace-seeking.yml new file mode 100644 index 00000000000..b753df4bb43 --- /dev/null +++ b/changelogs/unreleased/fix-trace-seeking.yml @@ -0,0 +1,4 @@ +--- +title: Fix invalid encoding when showing some traces +merge_request: 10681 +author: diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb index 41dcf846fed..3b335cdfd01 100644 --- a/lib/gitlab/ci/trace/stream.rb +++ b/lib/gitlab/ci/trace/stream.rb @@ -25,11 +25,10 @@ module Gitlab end def limit(last_bytes = LIMIT_SIZE) - stream_size = size - if stream_size < last_bytes - last_bytes = stream_size + if last_bytes < size + stream.seek(-last_bytes, IO::SEEK_END) + stream.readline end - stream.seek(-last_bytes, IO::SEEK_END) end def append(data, offset) diff --git a/spec/fixtures/trace/ansi-sequence-and-unicode b/spec/fixtures/trace/ansi-sequence-and-unicode new file mode 100644 index 00000000000..5d2466f0d0f --- /dev/null +++ b/spec/fixtures/trace/ansi-sequence-and-unicode @@ -0,0 +1,5 @@ +[0m[01;34m.[0m +[30;42m..[0m +😺 +ヾ(´༎ຶД༎ຶ`)ノ +[01;32m許功蓋[0m diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb index 2e57ccef182..9e3bd6d662f 100644 --- a/spec/lib/gitlab/ci/trace/stream_spec.rb +++ b/spec/lib/gitlab/ci/trace/stream_spec.rb @@ -17,12 +17,12 @@ describe Gitlab::Ci::Trace::Stream do describe '#limit' do let(:stream) do described_class.new do - StringIO.new("12345678") + StringIO.new((1..8).to_a.join("\n")) end end - it 'if size is larger we start from beggining' do - stream.limit(10) + it 'if size is larger we start from beginning' do + stream.limit(20) expect(stream.tell).to eq(0) end @@ -30,7 +30,27 @@ describe Gitlab::Ci::Trace::Stream do it 'if size is smaller we start from the end' do stream.limit(2) - expect(stream.tell).to eq(6) + expect(stream.raw).to eq("8") + end + + context 'when the trace contains ANSI sequence and Unicode' do + let(:stream) do + described_class.new do + File.open(expand_fixture_path('trace/ansi-sequence-and-unicode')) + end + end + + it 'forwards to the next linefeed, case 1' do + stream.limit(7) + + expect(stream.raw).to eq('') + end + + it 'forwards to the next linefeed, case 2' do + stream.limit(29) + + expect(stream.raw).to eq("\e[01;32m許功蓋\e[0m\n") + end end end diff --git a/spec/support/fixture_helpers.rb b/spec/support/fixture_helpers.rb index a05c9d18002..5515c355cea 100644 --- a/spec/support/fixture_helpers.rb +++ b/spec/support/fixture_helpers.rb @@ -1,8 +1,11 @@ module FixtureHelpers def fixture_file(filename) return '' if filename.blank? - file_path = File.expand_path(Rails.root.join('spec/fixtures/', filename)) - File.read(file_path) + File.read(expand_fixture_path(filename)) + end + + def expand_fixture_path(filename) + File.expand_path(Rails.root.join('spec/fixtures/', filename)) end end |