Permalink
Browse files

add AS::SafeBuffer#clone_empty

  • Loading branch information...
1 parent 7b73913 commit 621d2199599e9a3154ce6f6e81385bf574030f15 @amatsuda amatsuda committed with tenderlove Feb 13, 2012
@@ -119,6 +119,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)
@@ -116,4 +116,13 @@ def test_titleize
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

0 comments on commit 621d219

Please sign in to comment.