diff options
author | Sam Davies <seivadmas@gmail.com> | 2016-03-03 12:25:28 -0300 |
---|---|---|
committer | Sam Davies <seivadmas@gmail.com> | 2016-03-03 21:23:19 -0300 |
commit | fea7c9fed65b9dd305562483c1cfd80104d521b5 (patch) | |
tree | 63ed6da70a1ea9a833fc9b6217a0ba31db92ee77 /actionpack/lib/action_dispatch | |
parent | 3009fa1e089ff1133ce95c767063ca9f9cdb130f (diff) | |
download | rails-fea7c9fed65b9dd305562483c1cfd80104d521b5.tar.gz rails-fea7c9fed65b9dd305562483c1cfd80104d521b5.tar.bz2 rails-fea7c9fed65b9dd305562483c1cfd80104d521b5.zip |
Do not destructively mutate passed options hash in route definitions
- Fixes #24030
An example scope might be specified as such:
```ruby
HTML = { constraints: { format: :html } }.freeze
scope HTML do
get 'x'
end
```
This currently raises an error because the mapper attempts to
destructively modify the passed options hash. This is dangerous because
this options hash might even be shared with other scopes.
We should instead always instantiate a new object instead of modifying
the passed options.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 16b430c36e..c4621e386d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/enumerable' require 'active_support/core_ext/array/extract_options' @@ -824,7 +823,7 @@ module ActionDispatch URL_OPTIONS.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) end - (options[:defaults] ||= {}).reverse_merge!(defaults) + options[:defaults] = defaults.merge(options[:defaults] || {}) else block, options[:constraints] = options[:constraints], {} end |