diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/output_safety.rb | 8 | ||||
-rw-r--r-- | activesupport/test/safe_buffer_test.rb | 32 |
2 files changed, 38 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 3a80de4617..0b40c3d799 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -199,8 +199,12 @@ module ActiveSupport #:nodoc: super(html_escape_interpolated_argument(value)) end - def []=(index, value) - super(index, html_escape_interpolated_argument(value)) + def []=(*args) + if args.count == 3 + super(args[0], args[1], html_escape_interpolated_argument(args[2])) + else + super(args[0], html_escape_interpolated_argument(args[1])) + end end def +(other) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 08d04e3223..32e1d2d5bf 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -112,6 +112,38 @@ class SafeBufferTest < ActiveSupport::TestCase end end + test "can assign value into zero-index" do + buffer = ActiveSupport::SafeBuffer.new("012345") + + buffer[0] = "<" + + assert_equal "<12345", buffer + end + + test "can assign value into non zero-index" do + buffer = ActiveSupport::SafeBuffer.new("012345") + + buffer[2] = "<" + + assert_equal "01<345", buffer + end + + test "can assign value into slice" do + buffer = ActiveSupport::SafeBuffer.new("012345") + + buffer[0, 3] = "<" + + assert_equal "<345", buffer + end + + test "can assign value into offset slice" do + buffer = ActiveSupport::SafeBuffer.new("012345") + + buffer[1, 3] = "<" + + assert_equal "0<45", buffer + end + test "Should escape dirty buffers on add" do clean = "hello".html_safe @buffer.gsub!("", "<>") |