aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorRichard Monette <richard.monette@shopify.com>2019-03-13 18:28:43 -0400
committerRichard Monette <richard.monette@shopify.com>2019-03-13 19:22:04 -0400
commitaf2052295488fcd3dda88ef11ebd211cf777305f (patch)
treee423d0b8ab38de9a9c0103fb75ca60fe2adaa0d6 /activesupport/test
parenta783e4171241480324be575259de32a49d59405d (diff)
downloadrails-af2052295488fcd3dda88ef11ebd211cf777305f.tar.gz
rails-af2052295488fcd3dda88ef11ebd211cf777305f.tar.bz2
rails-af2052295488fcd3dda88ef11ebd211cf777305f.zip
support slice assignment on SafeBuffer
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/safe_buffer_test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index 08d04e3223..32e1d2d5bf 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -112,6 +112,38 @@ class SafeBufferTest < ActiveSupport::TestCase
end
end
+ test "can assign value into zero-index" do
+ buffer = ActiveSupport::SafeBuffer.new("012345")
+
+ buffer[0] = "<"
+
+ assert_equal "&lt;12345", buffer
+ end
+
+ test "can assign value into non zero-index" do
+ buffer = ActiveSupport::SafeBuffer.new("012345")
+
+ buffer[2] = "<"
+
+ assert_equal "01&lt;345", buffer
+ end
+
+ test "can assign value into slice" do
+ buffer = ActiveSupport::SafeBuffer.new("012345")
+
+ buffer[0, 3] = "<"
+
+ assert_equal "&lt;345", buffer
+ end
+
+ test "can assign value into offset slice" do
+ buffer = ActiveSupport::SafeBuffer.new("012345")
+
+ buffer[1, 3] = "<"
+
+ assert_equal "0&lt;45", buffer
+ end
+
test "Should escape dirty buffers on add" do
clean = "hello".html_safe
@buffer.gsub!("", "<>")