Skip to content

Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0 - #40663

Merged
amatsuda merged 1 commit into
rails:masterfrom
amatsuda:keep_safe_buffer
Dec 1, 2020
Merged

Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0#40663
amatsuda merged 1 commit into
rails:masterfrom
amatsuda:keep_safe_buffer

Conversation

@amatsuda

Copy link
Copy Markdown
Member

Summary

Ruby 3 introduces an incompatibility that all String methods return String instances when called on a subclass instance.
https://bugs.ruby-lang.org/issues/10845
ruby/ruby#3701

This slightly affects our ActiveSupport::SafeBuffer that subclasses String, and here's a patch for SafeBuffer#[] and SafeBuffer#* to preserve Ruby 2 behavior (= return another SafeBuffer instance) in Ruby 3.

Note that almost all other methods that were changed in Ruby 3.0 were overridden on SafeBuffer to return a String already, so only two methods here were needed to be patched for the tests to pass.

… in Ruby 3

Ruby 3 introduces an incompatibility that String methods return String instances when called on a subclass instance.
https://bugs.ruby-lang.org/issues/10845
ruby/ruby#3701
@eregon

eregon commented Nov 22, 2020

Copy link
Copy Markdown
Contributor

Looks good to me.
I'd like to suggest backporting this to Rails 5 once this is merged, so Rails 5 on Ruby 3 works fine.

@yahonda

yahonda commented Nov 22, 2020

Copy link
Copy Markdown
Member

@amatsuda
amatsuda merged commit 6f9d4a0 into rails:master Dec 1, 2020
@amatsuda
amatsuda deleted the keep_safe_buffer branch December 1, 2020 08:42
amatsuda added a commit that referenced this pull request Dec 1, 2020
Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0
amatsuda added a commit that referenced this pull request Dec 1, 2020
Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants