Commit b9950c22 authored by Shinya Maeda's avatar Shinya Maeda

Use each_line. Avoid comparison of partial. Add UTF-8 spec.

parent 14c0833c
......@@ -125,11 +125,10 @@ module Gitlab
stream.seek(-pos, IO::SEEK_END)
stream.read(BUFFER_SIZE).tap do |buf|
buf = buf + debris
lines = buf.split("\n")
lines.reverse.each do |line|
debris, *lines = buf.each_line.to_a
lines.reverse_each do |line|
yield(line)
end
debris = lines.count > 0 ? lines[0] : ''
end
pos += BUFFER_SIZE
end
......@@ -139,8 +138,7 @@ module Gitlab
last = (max > BUFFER_SIZE) ? (max % BUFFER_SIZE) : max
stream.read(last).tap do |buf|
buf = buf + debris
lines = buf.split("\n")
lines.reverse.each do |line|
buf.each_line.reverse_each do |line|
yield(line)
end
end
......
......@@ -265,6 +265,17 @@ describe Gitlab::Ci::Trace::Stream do
it { is_expected.to eq("98.29") }
end
context 'when regex is multi-byte char' do
let(:data) { 'ゴッドファット\n' }
let(:regex) { 'ゴッドファット' }
before do
stub_const('Gitlab::Ci::Trace::Stream::BUFFER_SIZE', 5)
end
it { is_expected.to be_nil }
end
context 'when BUFFER_SIZE is equal to stream.size' do
let(:data) { 'Coverage 1033 / 1051 LOC (98.29%) covered\n' }
let(:regex) { '\(\d+.\d+\%\) covered' }
......
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