aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/safe_buffer_test.rb
diff options
context:
space:
mode:
authorShugo Maeda <shugo@ruby-lang.org>2018-11-08 21:02:45 +0900
committerShugo Maeda <shugo@ruby-lang.org>2018-11-08 21:02:45 +0900
commit3891c725ade96b7a847ac133496ad307bd05e920 (patch)
tree0bf019cccbe7940432c40a012e3218167853649a /activesupport/test/safe_buffer_test.rb
parent7f7e7e8b39f56d35993bec4247ac0295cd0c943e (diff)
downloadrails-3891c725ade96b7a847ac133496ad307bd05e920.tar.gz
rails-3891c725ade96b7a847ac133496ad307bd05e920.tar.bz2
rails-3891c725ade96b7a847ac133496ad307bd05e920.zip
sub, sub!, gsub, and gsub! should set back references
Diffstat (limited to 'activesupport/test/safe_buffer_test.rb')
-rw-r--r--activesupport/test/safe_buffer_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index 49a3951623..9449adb6de 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -216,4 +216,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