diff options
4 files changed, 17 insertions, 5 deletions
| diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 2dcd6324db..0afdcd1def 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -326,7 +326,7 @@ module ActionView        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 - Module::RUBY_RESERVED_KEYWORDS          locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)          # Double assign to suppress the dreaded 'assigned but unused variable' warning diff --git a/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb b/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb new file mode 100644 index 0000000000..edfe52e422 --- /dev/null +++ b/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb @@ -0,0 +1 @@ +<%= _ %> <%= arg %> <%= args %> <%= block %>
\ No newline at end of file diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb index 3ecac46d34..40ac867b38 100644 --- a/actionview/test/template/compiled_templates_test.rb +++ b/actionview/test/template/compiled_templates_test.rb @@ -24,6 +24,16 @@ class CompiledTemplatesTest < ActiveSupport::TestCase      assert_equal locals.inspect, render(file: "test/render_file_inspect_local_assigns", locals: locals)    end +  def test_template_with_delegation_reserved_keywords +    locals = { +      _: "one", +      arg: "two", +      args: "three", +      block: "four", +    } +    assert_equal "one two three four", render(file: "test/test_template_with_delegation_reserved_keywords", locals: locals) +  end +    def test_template_with_unicode_identifier      assert_equal "🎂", render(file: "test/render_file_unicode_local", locals: { 🎃: "🎂" })    end diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index f5f4ba61b7..19f692e943 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -6,11 +6,12 @@ class Module    # option is not used.    class DelegationError < NoMethodError; end +  RUBY_RESERVED_KEYWORDS = %w(alias and BEGIN begin break case class def defined? do +  else elsif END end ensure false for if in module next nil not or redo rescue retry +  return self super then true undef unless until when while yield) +  DELEGATION_RESERVED_KEYWORDS = %w(_ arg args block)    DELEGATION_RESERVED_METHOD_NAMES = Set.new( -    %w(_ arg args alias and BEGIN begin block break case class def defined? do -       else elsif END end ensure false for if in module next nil not or redo -       rescue retry return self super then true undef unless until when while -       yield) +    RUBY_RESERVED_KEYWORDS + DELEGATION_RESERVED_KEYWORDS    ).freeze    # Provides a +delegate+ class method to easily expose contained objects' | 
