mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Preserve html_safe? status on ActiveSupport::SafeBuffer#*
This commit is contained in:
parent
98a75b4646
commit
9dd254c2a2
3 changed files with 26 additions and 0 deletions
|
@ -1,3 +1,15 @@
|
|||
* Preserve `html_safe?` status on `ActiveSupport::SafeBuffer#*`.
|
||||
|
||||
Before:
|
||||
|
||||
("<br />".html_safe * 2).html_safe? #=> nil
|
||||
|
||||
After:
|
||||
|
||||
("<br />".html_safe * 2).html_safe? #=> true
|
||||
|
||||
*Ryo Nakamura*
|
||||
|
||||
* Calling test methods with `with_info_handler` method to allow minitest-hooks
|
||||
plugin to work.
|
||||
|
||||
|
|
|
@ -213,6 +213,12 @@ module ActiveSupport #:nodoc:
|
|||
dup.concat(other)
|
||||
end
|
||||
|
||||
def *(*)
|
||||
new_safe_buffer = super
|
||||
new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
|
||||
new_safe_buffer
|
||||
end
|
||||
|
||||
def %(args)
|
||||
case args
|
||||
when Hash
|
||||
|
|
|
@ -150,6 +150,14 @@ class SafeBufferTest < ActiveSupport::TestCase
|
|||
assert_equal "hello<>", clean + @buffer
|
||||
end
|
||||
|
||||
test "Should preserve html_safe? status on multiplication" do
|
||||
multiplied_safe_buffer = "<br />".html_safe * 2
|
||||
assert_predicate multiplied_safe_buffer, :html_safe?
|
||||
|
||||
multiplied_unsafe_buffer = @buffer.gsub("", "<>") * 2
|
||||
assert_not_predicate multiplied_unsafe_buffer, :html_safe?
|
||||
end
|
||||
|
||||
test "Should concat as a normal string when safe" do
|
||||
clean = "hello".html_safe
|
||||
@buffer.gsub!("", "<>")
|
||||
|
|
Loading…
Reference in a new issue