Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for SafeBuffer#gsub and magic match globs

* to_str in preference of String.new
* tests + metaphorical exactitude
  • Loading branch information...
commit 1fa11344c5ba8f59d527c747f381ec69a77c8a1c 1 parent 5107f39
@tardate authored
View
2  activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -130,7 +130,7 @@ def #{unsafe_method}!(*args)
# If you really need the magic matching variables after the gsub call
# you will need to covert SafeBuffer to a String first
def gsub(*args)
- String.new(self).gsub(*args)
+ to_str.gsub(*args)
end
end
end
View
4 activesupport/test/safe_buffer_test.rb
@@ -52,13 +52,13 @@ def setup
end
test "Should set magic match variables within block passed to gsub" do
- 'clear'[/(matches)/]
+ 'burn'[/(matches)/]
@buffer << 'swan'
@buffer.gsub(/(swan)/) { assert_equal 'swan', $1 }
end
test "Should not expect magic match variables after gsub call" do
- 'clear'[/(matches)/]
+ 'burn'[/(matches)/]
@buffer << 'vesta'
@buffer.gsub(/(vesta)/, '')
assert !$1, %(
Please sign in to comment.
Something went wrong with that request. Please try again.