Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where nested scopes don't resolve parent context #95

Closed
wants to merge 1 commit into from

Conversation

jupp0r
Copy link

@jupp0r jupp0r commented Aug 6, 2016

This change fixes a bug where for the template

{{#each b}}{{#if ../../a}}{{#each this}}{{this}}{{/each}}{{/if}}{{/each}}

and the input

{"a": [{"b": true}], "b": [[1, 2, 3],[4, 5]]}

the output 123 would be produced. The correct output 12345
is produced after the fix. While this change definitely fixes the problem,
a cleaner solution would be to have RenderContext implement the Clone trait and cloning it in the call to render in the each helper.

This change fixes a bug where for the template

```
{{#each b}}{{#if ../../a}}{{#each this}}{{this}}{{/each}}{{/if}}{{/each}}
```

and the input

```
{"a": [{"b": true}], "b": [[1, 2, 3],[4, 5]]}
```

the output `123` would be produced. The correct output `12345`
is produced after the fix.
sunng87 added a commit that referenced this pull request Aug 7, 2016
Signed-off-by: Ning Sun <sunng@about.me>
@sunng87
Copy link
Owner

sunng87 commented Aug 7, 2016

Hi @jupp0r , thank you very much for this patch. As you said, a clone() function on RenderContext will fix this. So I added a derive function to RenderContext to clone all fields except writer.

There is a minor mistake in your template, the correct one is:
{{#each b}}{{#if ../a}}{{#each this}}{{this}}{{/each}}{{/if}}{{/each}}

This issue should be fixed in 84fd531 .

Thank you again for this patch.

@sunng87 sunng87 closed this Aug 7, 2016
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.

2 participants