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

Bracket notation will be reformatted even when dot notation is invalid #70

Closed
1 task done
evelynn-causemic opened this issue May 26, 2023 · 1 comment · Fixed by #77
Closed
1 task done

Bracket notation will be reformatted even when dot notation is invalid #70

evelynn-causemic opened this issue May 26, 2023 · 1 comment · Fixed by #77
Labels
bug Something isn't working

Comments

@evelynn-causemic
Copy link

Description

When accessing an object value using bracket notation, it will always be reformatted into dot notation, even if the key contains characters that are not valid in dot notation.

Expected behavior

Bracket notation should not be reformatted to use dot notation if the key contains spaces or other invalid characters.

To Reproduce

Original Source Code:

This will successfully print the value "baz".

{% set test_object = {
    "foo bar": "baz"
}%}
{{ test_object["foo bar"] }}

Formatted Source Code:

This will not print the value inside the object, and will present an error.

{% set test_object = {
    "foo bar": "baz"
}%}
{{ test_object.foo bar }}

Notes

As a matter of opinion, I'm not convinced that it's sensible to unilaterally enforce dot notation. While it is typically more readable, bracket notation can do some things that dot notation simply cannot (for example: text interpolation inside key values, accessing values whose keys contain syntactically significant characters). Without the ability to selectively disable formatting, this aggressive formatting rule effectively locks you out of that functionality.

Checklist

  • I have checked the known issues to make sure this isn’t already a known issue.
@j-malt
Copy link
Contributor

j-malt commented May 7, 2024

Hi Evelynn. Thank you for the report. This is fixed in #77 and should be released in the next version of the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants