From 6ef1079e0ed093e54a0e1dc9cb3b97d5e1330caf Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Fri, 29 Jul 2011 13:06:45 -0400 Subject: Reset @dirty to false when slicing an instance of SafeBuffer --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 6 ++++++ activesupport/test/safe_buffer_test.rb | 6 ++++++ 2 files changed, 12 insertions(+) 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 3bf4edbdef..6d6c4912bb 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -86,6 +86,12 @@ module ActiveSupport #:nodoc: end end + def[](*args) + new_safe_buffer = super + new_safe_buffer.instance_eval { @dirty = false } + new_safe_buffer + end + def safe_concat(value) raise SafeConcatError if dirty? original_concat(value) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 7662e9b765..8f77999d25 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -106,4 +106,10 @@ class SafeBufferTest < ActiveSupport::TestCase test "should not fail if the returned object is not a string" do assert_kind_of NilClass, @buffer.slice("chipchop") end + + test "Should initialize @dirty to false for new instance when sliced" do + dirty = @buffer[0,0].send(:dirty?) + assert_not_nil dirty + assert !dirty + end end -- cgit v1.2.3