From 000ddc96c5c9b58d898f6723bd122678d138e35d Mon Sep 17 00:00:00 2001
From: Nick Thomas <nick@gitlab.com>
Date: Fri, 21 Jul 2017 22:08:23 +0100
Subject: [PATCH] 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.
---
 lib/gitlab/ci/trace/stream.rb           | 1 +
 spec/lib/gitlab/ci/trace/stream_spec.rb | 7 +++++++
 2 files changed, 8 insertions(+)

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
-- 
GitLab