-
Notifications
You must be signed in to change notification settings - Fork 90
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
Dup frozen strings before force_encoding #196
Dup frozen strings before force_encoding #196
Conversation
@@ -23,7 +23,12 @@ def translate(locale, key, options) | |||
interpolate(translation, options) | |||
else | |||
result = backend.translate(locale, key, options) | |||
(RUBY19 and result.is_a?(String)) ? result.dup.force_encoding("UTF-8") : result | |||
if RUBY19 && result.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can delete all the if RUBY19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUBY19 cleanup can be it's own PR
On it's way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I18n 1.13.0 changed the behavior of interpolate to retain the original object when no interpolation occurs: https://github.com/ruby-i18n/i18n/pull/649/files With that change, a frozen string is no longer duplicated by i18n and retains the frozen state. This causes an error when we try to force_encoding as it's a modification in place. This worked previously because i18n interpolate would return a new unfrozen string from a frozen string input. ```ruby irb(main):003:0> I18n::VERSION => "1.13.0" irb(main):004:0> I18n.interpolate(("get".freeze), {}).frozen? => true ``` vs. ```ruby irb(main):002:0> I18n::VERSION => "1.12.0" irb(main):003:0> I18n.interpolate(("get".freeze), {}).frozen? => false ```
beb8cd2
to
84ea65e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks right!
RUBY19 cleanup can be it's own PR |
1.10.1 thanks! |
I18n 1.13.0 changed the behavior of interpolate to retain the original object when no interpolation occurs:
https://github.com/ruby-i18n/i18n/pull/649/files
With that change, a frozen string is no longer duplicated by i18n and retains the frozen state. This causes an error when we try to force_encoding as it's a modification in place. This worked previously because i18n interpolate would return a new unfrozen string from a frozen string input.
vs.