diff options
author | Matthew Draper <matthew@trebex.net> | 2016-10-02 21:10:26 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-02 21:10:26 +1030 |
commit | 7b63f56ce0c708f05db31de04b8cd2dc6e4ef96b (patch) | |
tree | 838e720c59e900a67064d13ee70af34a76b8d162 /actionview/lib/action_view/template.rb | |
parent | 832b02620b1331212a53186023688c8e84a4ca03 (diff) | |
parent | f9960f2d74b510e0d994d49377cec36301f7e7f0 (diff) | |
download | rails-7b63f56ce0c708f05db31de04b8cd2dc6e4ef96b.tar.gz rails-7b63f56ce0c708f05db31de04b8cd2dc6e4ef96b.tar.bz2 rails-7b63f56ce0c708f05db31de04b8cd2dc6e4ef96b.zip |
Merge pull request #26672 from schpet/support_ruby_keywords_as_template_locals
Avoid compiling ruby keywords into template locals
Diffstat (limited to 'actionview/lib/action_view/template.rb')
-rw-r--r-- | actionview/lib/action_view/template.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 513935cef0..c01dd1c028 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -1,5 +1,6 @@ require "active_support/core_ext/object/try" require "active_support/core_ext/kernel/singleton_class" +require "active_support/core_ext/module/delegation" require "thread" module ActionView @@ -324,8 +325,13 @@ module ActionView end def locals_code #:nodoc: + # Only locals with valid variable names get set directly. Others will + # still be available in local_assigns. + locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES + locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/) + # Double assign to suppress the dreaded 'assigned but unused variable' warning - @locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } + locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } end def method_name #:nodoc: |