Skip to content

Commit

Permalink
add AS::SafeBuffer#clone_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda authored and tenderlove committed Feb 21, 2012
1 parent 1be2bbe commit baf6903
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Expand Up @@ -101,6 +101,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)
Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/safe_buffer_test.rb
Expand Up @@ -102,4 +102,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

0 comments on commit baf6903

Please sign in to comment.