diff options
author | Matthew Draper <matthew@trebex.net> | 2019-03-28 23:32:52 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-28 23:32:52 +1030 |
commit | 78ace9cd080e626feb89ffb9e4142f0b672a53b3 (patch) | |
tree | e7f707ada6e49be2d52da916fc509a72690a72f4 /activesupport/test | |
parent | 19dbf44070b2b36d1cefba10d120e8b18c2599ab (diff) | |
parent | e7da1ddd6172fa36a8c0159652111b11745c81da (diff) | |
download | rails-78ace9cd080e626feb89ffb9e4142f0b672a53b3.tar.gz rails-78ace9cd080e626feb89ffb9e4142f0b672a53b3.tar.bz2 rails-78ace9cd080e626feb89ffb9e4142f0b672a53b3.zip |
Merge pull request #34405 from shugo/safe_buffer_backref_fix
sub, sub!, gsub, and gsub! should set back references
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/safe_buffer_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 32e1d2d5bf..b1a1c2d390 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -248,4 +248,22 @@ class SafeBufferTest < ActiveSupport::TestCase x = "Hello".html_safe assert_nil x[/a/, 1] end + + test "Should set back references" do + a = "foo123".html_safe + a2 = a.sub(/([a-z]+)([0-9]+)/) { $2 + $1 } + assert_equal "123foo", a2 + assert_not_predicate a2, :html_safe? + a.sub!(/([a-z]+)([0-9]+)/) { $2 + $1 } + assert_equal "123foo", a + assert_not_predicate a, :html_safe? + + b = "foo123 bar456".html_safe + b2 = b.gsub(/([a-z]+)([0-9]+)/) { $2 + $1 } + assert_equal "123foo 456bar", b2 + assert_not_predicate b2, :html_safe? + b.gsub!(/([a-z]+)([0-9]+)/) { $2 + $1 } + assert_equal "123foo 456bar", b + assert_not_predicate b, :html_safe? + end end |