Description: regexp using __FILE__ need to escape the filename if it contains
 special characters like +
Author: Cédric Boutillier <boutil@debian.org>
Forwarded: not-needed
Last-Update: 2016-03-02

--- a/rspec-core/spec/rspec/core/memoized_helpers_spec.rb
+++ b/rspec-core/spec/rspec/core/memoized_helpers_spec.rb
@@ -183,7 +183,7 @@
             end.run
 
             expect(result).to be_an(Exception)
-            expect(result.message).to match(/subject accessed.*#{hook}\(:context\).*#{__FILE__}:#{line}/m)
+            expect(result.message).to match(/subject accessed.*#{hook}\(:context\).*#{Regexp.escape(__FILE__)}:#{line}/m)
           end
         end
       end
@@ -559,7 +559,7 @@
         end.run
 
         expect(result).to be_an(Exception)
-        expect(result.message).to match(/let declaration `foo` accessed.*#{hook}\(:context\).*#{__FILE__}:#{line}/m)
+        expect(result.message).to match(/let declaration `foo` accessed.*#{hook}\(:context\).*#{Regexp.escape(__FILE__)}:#{line}/m)
       end
     end
 
--- a/rspec-core/lib/rspec/core/backtrace_formatter.rb
+++ b/rspec-core/lib/rspec/core/backtrace_formatter.rb
@@ -16,7 +16,7 @@
         @inclusion_patterns = []
 
         return unless matches?(@exclusion_patterns, File.join(Dir.getwd, "lib", "foo.rb:13"))
-        inclusion_patterns << Regexp.new(Dir.getwd)
+        inclusion_patterns << Regexp.new(Regexp.escape(Dir.getwd))
       end
 
       attr_writer :full_backtrace
--- a/rspec-support/spec/rspec/support/warnings_spec.rb
+++ b/rspec-support/spec/rspec/support/warnings_spec.rb
@@ -41,7 +41,7 @@
     end
 
     it 'sets the calling line' do
-      expect(::Kernel).to receive(:warn).with(/#{__FILE__}:#{__LINE__+1}/)
+      expect(::Kernel).to receive(:warn).with(/#{Regexp.escape(__FILE__)}:#{__LINE__+1}/)
       warning_object.send(helper, 'Message')
     end
 
--- a/rspec-core/spec/rspec/core/rake_task_spec.rb
+++ b/rspec-core/spec/rspec/core/rake_task_spec.rb
@@ -34,7 +34,7 @@
 
     context "default" do
       it "renders rspec" do
-        expect(spec_command).to match(/^#{ruby} '?#{task.rspec_path}'?/)
+        expect(spec_command).to match(/^#{ruby} '?#{Regexp.escape(task.rspec_path.shellescape)}'?/)
       end
     end
 
@@ -55,7 +55,7 @@
     context "with ruby options" do
       it "renders them before the rspec path" do
         task.ruby_opts = "-w"
-        expect(spec_command).to match(/^#{ruby} -w '?#{task.rspec_path}'?/)
+        expect(spec_command).to match(/^#{ruby} -w '?#{Regexp.escape(task.rspec_path.shellescape)}'?/)
       end
     end
 
--- a/rspec-core/spec/rspec/core/example_spec.rb
+++ b/rspec-core/spec/rspec/core/example_spec.rb
@@ -130,7 +130,7 @@
         RSpec.configuration.format_docstrings { |s| s.upcase }
         example_group.example { }
         example_group.run
-        pattern = /EXAMPLE AT #{relative_path(__FILE__).upcase}:#{__LINE__ - 2}/
+        pattern = /EXAMPLE AT #{Regexp.escape(relative_path(__FILE__).upcase)}:#{__LINE__ - 2}/
         expect(example_group.examples.first.description).to match(pattern)
       end
     end
@@ -153,14 +153,14 @@
       it "uses the file and line number if there is no matcher-generated description" do
         example = example_group.example {}
         example_group.run
-        expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
+        expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 2}/)
       end
 
       it "uses the file and line number if there is an error before the matcher" do
         example = example_group.example { expect(5).to eq(5) }
         example_group.before { raise }
         example_group.run
-        expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
+        expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 3}/)
       end
 
       context "if the example is pending" do
@@ -173,7 +173,7 @@
         it "uses the file and line number of the example if no matcher ran" do
           example = example_group.example { pending; fail }
           example_group.run
-          expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
+          expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 2}/)
         end
       end
 
@@ -239,14 +239,14 @@
       it "uses the file and line number if there is no matcher-generated description" do
         example = example_group.example {}
         example_group.run
-        expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
+        expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 2}/)
       end
 
       it "uses the file and line number if there is an error before the matcher" do
         example = example_group.example { expect(5).to eq(5) }
         example_group.before { raise }
         example_group.run
-        expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
+        expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 3}/)
       end
     end
 
@@ -278,7 +278,7 @@
       it "uses the file and line number" do
         example = example_group.example { assert 5 == 5 }
         example_group.run
-        expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
+        expect(example.description).to match(/example at #{Regexp.escape(relative_path(__FILE__))}:#{__LINE__ - 2}/)
       end
     end
   end
--- a/rspec-core/spec/rspec/core/configuration_spec.rb
+++ b/rspec-core/spec/rspec/core/configuration_spec.rb
@@ -61,7 +61,7 @@
 
         it 'prints a notice indicating the reconfigured output_stream will be ignored' do
           config.deprecation_stream = double("IO")
-          expect(config).to have_received(:warn).with(/deprecation_stream.*#{__FILE__}:#{__LINE__ - 1}/)
+          expect(config).to have_received(:warn).with(/deprecation_stream.*#{Regexp.escape(__FILE__)}:#{__LINE__ - 1}/)
         end
 
         it 'does not change the value of `deprecation_stream`' do
@@ -96,7 +96,7 @@
 
         it 'prints a notice indicating the reconfigured output_stream will be ignored' do
           config.output_stream = StringIO.new
-          expect(config).to have_received(:warn).with(/output_stream.*#{__FILE__}:#{__LINE__ - 1}/)
+          expect(config).to have_received(:warn).with(/output_stream.*#{Regexp.escape(__FILE__)}:#{__LINE__ - 1}/)
         end
 
         it 'does not change the value of `output_stream`' do
--- a/rspec-core/lib/rspec/core/metadata.rb
+++ b/rspec-core/lib/rspec/core/metadata.rb
@@ -34,7 +34,7 @@
       # http://rubular.com/r/duOrD4i3wb
       # http://rubular.com/r/sbAMHFrOx1
       def self.relative_path_regex
-        @relative_path_regex ||= /(\A|\s)#{File.expand_path('.')}(#{File::SEPARATOR}|\s|\Z)/
+        @relative_path_regex ||= /(\A|\s)#{Regexp.escape(File.expand_path('.'))}(#{File::SEPARATOR}|\s|\Z)/
       end
 
       # @api private
--- a/rspec-support/lib/rspec/support/spec/deprecation_helpers.rb
+++ b/rspec-support/lib/rspec/support/spec/deprecation_helpers.rb
@@ -50,7 +50,7 @@
   def expect_warning_with_call_site(file, line, expected=//)
     expect(::Kernel).to receive(:warn) do |message|
       expect(message).to match expected
-      expect(message).to match(/Called from #{file}:#{line}/)
+      expect(message).to match(/Called from #{Regexp.escape(file)}:#{line}/)
     end
   end
 
--- a/rspec-mocks/spec/rspec/mocks/and_call_original_spec.rb
+++ b/rspec-mocks/spec/rspec/mocks/and_call_original_spec.rb
@@ -68,7 +68,7 @@
     end
 
     it 'warns when you override an existing implementation' do
-      expect(RSpec).to receive(:warning).with(/overriding a previous stub implementation of `meth_1`.*#{__FILE__}:#{__LINE__ + 1}/)
+      expect(RSpec).to receive(:warning).with(/overriding a previous stub implementation of `meth_1`.*#{Regexp.escape(__FILE__)}:#{__LINE__ + 1}/)
       expect(instance).to receive(:meth_1) { true }.and_call_original
       instance.meth_1
     end
--- a/rspec-mocks/spec/rspec/mocks/matchers/receive_messages_spec.rb
+++ b/rspec-mocks/spec/rspec/mocks/matchers/receive_messages_spec.rb
@@ -92,7 +92,7 @@
 
       it 'fails with the correct location' do
         expect(obj).to receive_messages(:a => 1, :b => 2); line = __LINE__
-        expect(expectation_error.backtrace[0]).to match(/#{__FILE__}:#{line}/)
+        expect(expectation_error.backtrace[0]).to match(/#{Regexp.escape(__FILE__)}:#{line}/)
       end
 
       it_behaves_like "complains when given blocks"
--- a/rspec-mocks/spec/rspec/mocks/combining_implementation_instructions_spec.rb
+++ b/rspec-mocks/spec/rspec/mocks/combining_implementation_instructions_spec.rb
@@ -158,7 +158,7 @@
       end
 
       it 'warns when the inner implementation block is overriden' do
-        expect(RSpec).to receive(:warning).with(/overriding a previous stub implementation of `foo`.*#{__FILE__}:#{__LINE__ + 1}/)
+        expect(RSpec).to receive(:warning).with(/overriding a previous stub implementation of `foo`.*#{Regexp.escape(__FILE__)}:#{__LINE__ + 1}/)
         allow(double).to receive(:foo).with(:arg) { :with_block }.at_least(:once) { :at_least_block }
       end
 
--- a/rspec-mocks/spec/rspec/mocks/nil_expectation_warning_spec.rb
+++ b/rspec-mocks/spec/rspec/mocks/nil_expectation_warning_spec.rb
@@ -6,7 +6,7 @@
           expect(nil).to receive(:foo)
         }.to output(a_string_including(
           "An expectation of `:foo` was set on `nil`",
-          "#{__FILE__}:#{__LINE__ - 3}"
+          "#{Regexp.escape(__FILE__)}:#{__LINE__ - 3}"
         )).to_stderr
 
         nil.foo
@@ -17,7 +17,7 @@
           expect(nil).not_to receive(:foo)
         }.to output(a_string_including(
           "An expectation of `:foo` was set on `nil`",
-          "#{__FILE__}:#{__LINE__ - 3}"
+          "#{Regexp.escape(__FILE__)}:#{__LINE__ - 3}"
         )).to_stderr
       end
 
@@ -76,7 +76,7 @@
           expect(nil).to receive(:foo)
         }.to output(a_string_including(
           "An expectation of `:foo` was set on `nil`",
-          "#{__FILE__}:#{__LINE__ - 3}"
+          "#{Regexp.escape(__FILE__)}:#{__LINE__ - 3}"
         )).to_stderr
 
         nil.foo
