aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/safe_buffer_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-02-29 22:30:51 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-29 16:09:02 -0800
commit8ccaa34103f1c37f7549f7f6c47a21dba21624db (patch)
tree00001858b028ab34fb66e6563817490a9ec23509 /activesupport/test/safe_buffer_test.rb
parent71d8c77e5ac74c2aa20eff6b3d6a8b8ca24114d7 (diff)
downloadrails-8ccaa34103f1c37f7549f7f6c47a21dba21624db.tar.gz
rails-8ccaa34103f1c37f7549f7f6c47a21dba21624db.tar.bz2
rails-8ccaa34103f1c37f7549f7f6c47a21dba21624db.zip
Ensure [] respects the status of the buffer.
Diffstat (limited to 'activesupport/test/safe_buffer_test.rb')
-rw-r--r--activesupport/test/safe_buffer_test.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index 56f9a9a51a..047b89be2a 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -84,13 +84,13 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_equal "hello&lt;&gt;", clean + @buffer
end
- test "Should concat as a normal string when dirty" do
+ test "Should concat as a normal string when safe" do
clean = "hello".html_safe
@buffer.gsub!('', '<>')
assert_equal "<>hello", @buffer + clean
end
- test "Should preserve dirty? status on copy" do
+ test "Should preserve html_safe? status on copy" do
@buffer.gsub!('', '<>')
assert !@buffer.dup.html_safe?
end
@@ -102,14 +102,14 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_equal "<script>", result_buffer
end
- test "Should raise an error when safe_concat is called on dirty buffers" do
+ test "Should raise an error when safe_concat is called on unsafe buffers" do
@buffer.gsub!('', '<>')
assert_raise ActiveSupport::SafeBuffer::SafeConcatError do
@buffer.safe_concat "BUSTED"
end
end
- test "should not fail if the returned object is not a string" do
+ test "Should not fail if the returned object is not a string" do
assert_kind_of NilClass, @buffer.slice("chipchop")
end
@@ -121,4 +121,23 @@ class SafeBufferTest < ActiveSupport::TestCase
assert @buffer.clone_empty.html_safe?
assert !@buffer.gsub!('', '').clone_empty.html_safe?
end
+
+ test "Should be safe when sliced if original value was safe" do
+ new_buffer = @buffer[0,0]
+ assert_not_nil new_buffer
+ assert new_buffer.html_safe?, "should be safe"
+ end
+
+ test "Should continue unsafe on slice" do
+ x = 'foo'.html_safe.gsub!('f', '<script>alert("lolpwnd");</script>')
+
+ # calling gsub! makes the dirty flag true
+ assert !x.html_safe?, "should not be safe"
+
+ # getting a slice of it
+ y = x[0..-1]
+
+ # should still be unsafe
+ assert !y.html_safe?, "should not be safe"
+ end
end