Skip to content

Commit

Permalink
Merge pull request #40663 from amatsuda/keep_safe_buffer
Browse files Browse the repository at this point in the history
Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0
  • Loading branch information
amatsuda committed Dec 1, 2020
2 parents 4cb2084 + a4d2493 commit 6f9d4a0
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -152,12 +152,12 @@ def initialize

def [](*args)
if html_safe?
new_safe_buffer = super
new_string = super

if new_safe_buffer
new_safe_buffer.instance_variable_set :@html_safe, true
end
return unless new_string

new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
new_safe_buffer.instance_variable_set :@html_safe, true
new_safe_buffer
else
to_str[*args]
Expand Down Expand Up @@ -213,7 +213,8 @@ def +(other)
end

def *(*)
new_safe_buffer = super
new_string = super
new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
new_safe_buffer
end
Expand Down

0 comments on commit 6f9d4a0

Please sign in to comment.