mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
SafeBuffer should maintain safety upon getting a slice via a range if original buffer was safe.
Co-Authored-By: no-itsbackpack <no-itsbackpack@github.com>
This commit is contained in:
parent
12fadea8ae
commit
3f5bd11ed6
2 changed files with 13 additions and 3 deletions
|
@ -149,9 +149,7 @@ module ActiveSupport #:nodoc:
|
|||
end
|
||||
|
||||
def [](*args)
|
||||
if args.size < 2
|
||||
super
|
||||
elsif html_safe?
|
||||
if html_safe?
|
||||
new_safe_buffer = super
|
||||
|
||||
if new_safe_buffer
|
||||
|
|
|
@ -150,6 +150,18 @@ class SafeBufferTest < ActiveSupport::TestCase
|
|||
assert_not y.html_safe?, "should not be safe"
|
||||
end
|
||||
|
||||
test "Should continue safe on slice" do
|
||||
x = "<div>foo</div>".html_safe
|
||||
|
||||
assert x.html_safe?, "should be safe"
|
||||
|
||||
# getting a slice of it
|
||||
y = x[0..-1]
|
||||
|
||||
# should still be safe
|
||||
assert y.html_safe?, "should be safe"
|
||||
end
|
||||
|
||||
test "Should work with interpolation (array argument)" do
|
||||
x = "foo %s bar".html_safe % ["qux"]
|
||||
assert_equal "foo qux bar", x
|
||||
|
|
Loading…
Reference in a new issue