From f9e06897adfa550f675fdaa0166ec25f2add28f5 Mon Sep 17 00:00:00 2001
From: Mark Lapierre <mlapierre@gitlab.com>
Date: Mon, 6 May 2019 13:07:31 +1000
Subject: [PATCH] Escape arg used in regex

---
 qa/qa/git/repository.rb        | 2 +-
 qa/spec/git/repository_spec.rb | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb
index b3bad40a90f..84353e3d0c7 100644
--- a/qa/qa/git/repository.rb
+++ b/qa/qa/git/repository.rb
@@ -251,7 +251,7 @@ module QA
       end
 
       def netrc_already_contains_content?
-        read_netrc_content.grep(/^#{netrc_content}$/).any?
+        read_netrc_content.grep(/^#{Regexp.escape(netrc_content)}$/).any?
       end
     end
   end
diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository_spec.rb
index 776dce31d4f..fd77681797f 100644
--- a/qa/spec/git/repository_spec.rb
+++ b/qa/spec/git/repository_spec.rb
@@ -116,6 +116,15 @@ describe QA::Git::Repository do
         expect(File.read(File.join(tmp_netrc_dir, '.netrc')))
           .to eq("machine foo login user password foo\n")
       end
+
+      it 'adds credentials with special characters' do
+        password = %q(!"#$%&'()*+,-./:;<=>?)
+        repository.username = 'user'
+        repository.password = password
+
+        expect(File.read(File.join(tmp_netrc_dir, '.netrc')))
+          .to eq("machine foo login user password #{password}\n")
+      end
     end
   end
 end
-- 
2.30.9