Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

amatsuda
Copy link
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
Copy link
Contributor

eregon commented Nov 22, 2020

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
Copy link
Member

yahonda commented Nov 22, 2020

Confirmed this pull request addresses the CI failure at https://buildkite.com/rails/rails/builds/72947#6a6a6523-71a1-4e64-9de2-597a161f0aaa

@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.

None yet

3 participants