Skip to content

fix: resolve block parameters named like context variables - #671

Open
jsneedles wants to merge 1 commit into
Handlebars-Net:masterfrom
jsneedles:fix/block_params_param_lookup
Open

jsneedles wants to merge 1 commit into
Handlebars-Net:masterfrom
jsneedles:fix/block_params_param_lookup

Conversation

@jsneedles

Copy link
Copy Markdown

Block parameters such as index could resolve to another parameter’s value or nothing. The lookup reused an entry index from ContextDataObject against BlockParamsObject, where hash collisions could place the same name in a different slot.

Resolve block parameters by name, matching TryGetContextVariable.

Adds regression coverage for index, key, first, last, root, and parent. Reproducing the original failure depends on the process’s randomized string hash seed.

Validation: all 5 focused test cases pass.

Split from #670.

fix: resolve block params named like @-variables by name

Unrelated to the JsonNode changes in this PR. The new JSON array iteration tests use `as |item index|`, which exposed this bug as an intermittent CI failure.

A block param that shares a name with a context variable (e.g. `{{#each items as |item index|}}`) was looked up in BlockParamsObject using the entry index of the matching @-variable in ContextDataObject. The two dictionaries usually place the key in the same slot, so this mostly worked, but when a hash collision moved the @-variable's slot, the lookup returned another block param's value or nothing. String hashes are randomized per process, so the failure was intermittent on every OS.

Look block params up by segment, as TryGetContextVariable already does. Adds a regression test covering index, key, first, last, root and parent. Because the bug depends on the process hash seed, the test cannot fail deterministically without the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant