1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
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
|