FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Preserve identifiers when reconstructing a tag which sets a value by jasmith-hs · Pull Request #988 · HubSpot/jinjava · GitHub

Preserve identifiers when reconstructing a tag which sets a value - #988

Merged
jasmith-hs merged 6 commits into
masterfrom
preserve-identifiers
Jan 12, 2023
Merged

Preserve identifiers when reconstructing a tag which sets a value#988
jasmith-hs merged 6 commits into
masterfrom
preserve-identifiers

Conversation

Copy link
Copy Markdown
Contributor

When reconstructing a tag which has the function of setting a variable to the result of an expression (both set and for do this), we should preserve the AstIdentifiers in the expression rather than resolving them because they may be directly referencing a value which can be modified later on. If instead, we set our variable to a serialized version of the object, then if that object is modified, the changes will not be reflected in the set value.

The simplest example of this is shown in one of the new tests:

{% set dict = {} %}

{% set foo = (dict, deferred) %}

{% do dict.update({'a': 'b'}) %}

{{ foo }}

If we don't preserve the identifier for dict, then we end up with:

{% set dict = {} %}

{% set foo = ({}, deferred) %}

{% do dict.update({'a': 'b'}) %}

{{ foo }}

Which would result in foo not having the correct value within it!

I realised that this can also happen if a value is reconstructed and then later one of the elements inside of that value is updated. Such a case is much more difficult to handle. I created a separate issue for that: #987

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL