aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb6
-rw-r--r--activesupport/test/safe_buffer_test.rb9
2 files changed, 15 insertions, 0 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 dd780da157..20c2befc57 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -124,6 +124,12 @@ module ActiveSupport #:nodoc:
@dirty = other.dirty?
end
+ def clone_empty
+ new_safe_buffer = self[0, 0]
+ new_safe_buffer.instance_variable_set(:@dirty, @dirty)
+ new_safe_buffer
+ end
+
def concat(value)
if dirty? || value.html_safe?
super(value)
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index bdde5141a9..ff36af5c40 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -118,4 +118,13 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_not_nil dirty
assert !dirty
end
+
+ test "clone_empty returns an empty buffer" do
+ assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty
+ end
+
+ test "clone_empty keeps the original dirtyness" do
+ assert @buffer.clone_empty.html_safe?
+ assert !@buffer.gsub!('', '').clone_empty.html_safe?
+ end
end