aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/safe_buffer_test.rb
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2014-12-29 18:31:34 +0530
committerVipul A M <vipulnsward@gmail.com>2014-12-29 18:31:34 +0530
commit983674667a21ee2e4e6a43282507858634dce907 (patch)
tree9dc977bf61224ffcaf93a714971c877b72482c9d /activesupport/test/safe_buffer_test.rb
parentb67b57d47368b4b834cfe8c58d9e26f5c819c154 (diff)
downloadrails-983674667a21ee2e4e6a43282507858634dce907.tar.gz
rails-983674667a21ee2e4e6a43282507858634dce907.tar.bz2
rails-983674667a21ee2e4e6a43282507858634dce907.zip
When trying to access a character on a string buffer object via `:[]`, if the object being accessed currently returns `html_safe?` as true,
we used to set `@html_safe` variable as true on new object created. When doing something like x = 'Hello'.html_safe x[/a/, 1] would throw an error on ruby 2.2, since when nothign gets matched nil is returned by the code and it tries to set `@html_safe` value to true, which would error since starting 2.2 nil is frozen. This change adds a safety net to avoid setting `@html_safe = true` on frozen objects. Fixes #18235
Diffstat (limited to 'activesupport/test/safe_buffer_test.rb')
-rw-r--r--activesupport/test/safe_buffer_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index efa9d5e61f..fca4b45276 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -165,4 +165,13 @@ class SafeBufferTest < ActiveSupport::TestCase
x = 'foo %{x} bar'.html_safe % { x: 'qux' }
assert x.html_safe?, 'should be safe'
end
+
+ test 'Should not affect frozen objects when accessing characters' do
+ x = 'Hello'.html_safe
+ assert_nothing_raised do
+ x[/a/, 1]
+ end
+ end
+
+
end