diff options
author | Nick Thomas <nick@gitlab.com> | 2017-07-21 22:08:23 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-07-21 22:08:23 +0100 |
commit | 000ddc96c5c9b58d898f6723bd122678d138e35d (patch) | |
tree | 4ea2d40f75419d606d58bf87199e68117b1d640a | |
parent | 2209426f7ba1a0c40b09e5b67ac3b48fd15f7b99 (diff) | |
download | gitlab-ce-000ddc96c5c9b58d898f6723bd122678d138e35d.tar.gz |
Fix the gcovr coverage regex by removing line separators before scanning
RE2 differs from Ruby in handling multiple-line strings. The string "foo\n"
will not match the regular expression "foo$" unless multi-line mode is enabled
(and it's off by default).
Since we're already scanning the build trace line by line (and so multi-line
coverage regular expressions won't work), we can fix this by removing the line
separator before scanning the string.
-rw-r--r-- | lib/gitlab/ci/trace/stream.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/trace/stream_spec.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb index 5d6977106d6..aaba034474c 100644 --- a/lib/gitlab/ci/trace/stream.rb +++ b/lib/gitlab/ci/trace/stream.rb @@ -74,6 +74,7 @@ module Gitlab match = "" reverse_line do |line| + line.chomp! matches = regex.scan(line) next unless matches.is_a?(Array) next if matches.empty? diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb index 13f0338b6aa..3a132fb9989 100644 --- a/spec/lib/gitlab/ci/trace/stream_spec.rb +++ b/spec/lib/gitlab/ci/trace/stream_spec.rb @@ -300,5 +300,12 @@ describe Gitlab::Ci::Trace::Stream do include_examples 'malicious regexp' end + + context 'multi-line data with rooted regexp' do + let(:data) { "\n65%\n" } + let(:regex) { '^(\d+)\%$' } + + it { is_expected.to eq('65') } + end end end |