-
Alex Ghiculescu authored
https://github.com/rails/rails/commit/3d00c8b97f3b18d89cdeaebe3d07661300ab14e4 introduced a regression: ```ruby ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym("API") end ``` If you have a controller called `APIController`, you may get a crash backtrace that looks like this: ``` FrozenError: can't modify frozen String: "API" rails (b8a399cd) actionpack/lib/action_dispatch/http/request.rb:89:in `controller_class_for' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:100:in `action_encoding_template' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:85:in `encode' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:45:in `set_binary_encoding' rails (b8a399cd) actionpack/lib/action_dispatch/http/parameters.rb:68:in `path_parameters=' ``` And you can see the issue in action like this: ```ruby Tanda @ Rails 7.1.0.alpha (test) :004 > "API".freeze.underscore.frozen? false # this is expected Tanda @ Rails 7.1.0.alpha (test) :004 > "API".freeze.underscore.camelize.frozen? false # this is *not* expected, and is what causes the above code to crash ``` I think the correct behaviour is for the inflector to always return non-frozen strings, even if it's using a cached frozen string as is the case in https://github.com/rails/rails/commit/3d00c8b97f3b18d89cdeaebe3d07661300ab14e4 Other semi-related PRs: https://github.com/rails/rails/pull/41174, https://github.com/rails/rails/pull/41881 cc @amatsuda @byroot
Alex Ghiculescu authoredhttps://github.com/rails/rails/commit/3d00c8b97f3b18d89cdeaebe3d07661300ab14e4 introduced a regression: ```ruby ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym("API") end ``` If you have a controller called `APIController`, you may get a crash backtrace that looks like this: ``` FrozenError: can't modify frozen String: "API" rails (b8a399cd) actionpack/lib/action_dispatch/http/request.rb:89:in `controller_class_for' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:100:in `action_encoding_template' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:85:in `encode' rails (b8a399cd) actionpack/lib/action_dispatch/request/utils.rb:45:in `set_binary_encoding' rails (b8a399cd) actionpack/lib/action_dispatch/http/parameters.rb:68:in `path_parameters=' ``` And you can see the issue in action like this: ```ruby Tanda @ Rails 7.1.0.alpha (test) :004 > "API".freeze.underscore.frozen? false # this is expected Tanda @ Rails 7.1.0.alpha (test) :004 > "API".freeze.underscore.camelize.frozen? false # this is *not* expected, and is what causes the above code to crash ``` I think the correct behaviour is for the inflector to always return non-frozen strings, even if it's using a cached frozen string as is the case in https://github.com/rails/rails/commit/3d00c8b97f3b18d89cdeaebe3d07661300ab14e4 Other semi-related PRs: https://github.com/rails/rails/pull/41174, https://github.com/rails/rails/pull/41881 cc @amatsuda @byroot
Loading