这是indexloc提供的服务,不要输入任何密码
Skip to content

[BUG] I18n.fallbacks should not be mutable #717

@alexfiennes

Description

@alexfiennes

What I tried to do

teamskills(dev)> I18n.locale
=> :en
teamskills(dev)> fallbacks = I18n.fallbacks[I18n.locale]
=> [:en, :"en-US"]
teamskills(dev)> fallbacks.concat([:wtf])
=> [:en, :"en-US", :wtf]
teamskills(dev)> I18n.fallbacks[I18n.locale]
=> [:en, :"en-US", :wtf]

What I expected to happen

I would either expect that the array that is returned from I18n.fallbacks is a dup of the original one so that I can mutate it without poisoning future requests, or that the array that is returned is frozen so that it can't be mutated.

I personally would prefer the frozen array so that we don't incur the overhead of duplicating the array on each request if we probably aren't going to mutate it.

I can make a PR once we have decided which behaviour we prefer.

What actually happened

The array that is returned is mutable and if I mutate it then the mutated array is returned for future requests.

Versions of i18n, rails, and anything else you think is necessary

i18n version 1.14.7
rails 7.2.2.1
ruby 3.4.2


Bonus points for providing an application or a small code example which reproduces the issue.

Thanks! ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions