Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add AS::SafeBuffer#clone_empty

  • Loading branch information...
commit e50ee96a0b37e7c5adfc555edd402ad04cc159f1 1 parent 5b4082f
Akira Matsuda amatsuda authored tenderlove committed
6 activesupport/lib/active_support/core_ext/string/output_safety.rb
View
@@ -100,6 +100,12 @@ def initialize_copy(other)
@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)
9 activesupport/test/safe_buffer_test.rb
View
@@ -83,4 +83,13 @@ def setup
@buffer.safe_concat "BUSTED"
end
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
Please sign in to comment.
Something went wrong with that request. Please try again.