Skip to content

Commit 4278982

Browse files
committed
ActionView::Template fix computation of strict locals
Fix: rails#49782 There was a bug in how we computed the list of required keys which wasn't caught by the test.
1 parent 8f9c561 commit 4278982

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

actionview/lib/action_view/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def compile(mod)
501501
end
502502

503503
unless parameters.any? { |type, _| type == :keyrest }
504-
parameters.map!(&:first)
504+
parameters.map!(&:last)
505505
parameters.sort!
506506
@strict_local_keys = parameters.freeze
507507
end

actionview/test/template/template_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ def test_rails_injected_locals_can_be_specified_as_kwargs
215215
assert_equal "1-2", render(message: "Hello", message_counter: 1, message_iteration: 2, implicit_locals: %i[message_counter message_iteration])
216216
end
217217

218+
def test_rails_injected_locals_can_be_specified_as_required_argument
219+
@template = new_template("<%# locals: (message: 'Hello', message_iteration:) -%>\n<%= message %>-<%= message_iteration %>")
220+
assert_equal "Hello-2", render(message: "Hello", message_counter: 1, message_iteration: 2, implicit_locals: %i[message_counter message_iteration])
221+
end
222+
218223
# TODO: This is currently handled inside ERB. The case of explicitly
219224
# lying about encodings via the normal Rails API should be handled
220225
# inside Rails.

0 commit comments

Comments
 (0)