Permalink
Browse files

Reset @dirty to false when slicing an instance of SafeBuffer

  • Loading branch information...
1 parent 270fa63 commit 6ef1079e0ed093e54a0e1dc9cb3b97d5e1330caf @bcardarella bcardarella committed Jul 29, 2011
@@ -86,6 +86,12 @@ def initialize
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)
@@ -106,4 +106,10 @@ def setup
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

0 comments on commit 6ef1079

Please sign in to comment.