Skip to content

Commit

Permalink
Merge pull request #50058 from Shopify/fix-implicit-strict-locals-again
Browse files Browse the repository at this point in the history
ActionView::Template fix computation of strict locals
  • Loading branch information
byroot committed Nov 14, 2023
1 parent 78dc56d commit 0c94806
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions actionview/CHANGELOG.md
@@ -1,3 +1,9 @@
* Fix detection of required strict locals

Further fix `render @collection` compatibility with strict locals

*Jean Boussier*

## Rails 7.1.2 (November 10, 2023) ##

* Fix the `number_to_human_size` view helper to correctly work with negative numbers.
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template.rb
Expand Up @@ -501,7 +501,7 @@ def compile(mod)
end

unless parameters.any? { |type, _| type == :keyrest }
parameters.map!(&:first)
parameters.map!(&:last)
parameters.sort!
@strict_local_keys = parameters.freeze
end
Expand Down
5 changes: 5 additions & 0 deletions actionview/test/template/template_test.rb
Expand Up @@ -215,6 +215,11 @@ def test_rails_injected_locals_can_be_specified_as_kwargs
assert_equal "1-2", render(message: "Hello", message_counter: 1, message_iteration: 2, implicit_locals: %i[message_counter message_iteration])
end

def test_rails_injected_locals_can_be_specified_as_required_argument
@template = new_template("<%# locals: (message: 'Hello', message_iteration:) -%>\n<%= message %>-<%= message_iteration %>")
assert_equal "Hello-2", render(message: "Hello", message_counter: 1, message_iteration: 2, implicit_locals: %i[message_counter message_iteration])
end

# TODO: This is currently handled inside ERB. The case of explicitly
# lying about encodings via the normal Rails API should be handled
# inside Rails.
Expand Down

0 comments on commit 0c94806

Please sign in to comment.