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

Error When Accessing Subproperty of Bracketed Reference #643

Closed
gtowne opened this issue Aug 18, 2023 · 5 comments
Closed

Error When Accessing Subproperty of Bracketed Reference #643

gtowne opened this issue Aug 18, 2023 · 5 comments

Comments

@gtowne
Copy link

gtowne commented Aug 18, 2023

I'm seeing what appears to be a parsing error when trying to access a subproperty of an object where the top-level key is wrapped in brackets. Here a minimal repro in the LiquidJS playground that demonstrates the error.

Template Value

{{ ["Key String with Spaces"].subproperty_key }}

Scope Object

{
    "Key String with Spaces": {
      "subproperty_key": "subproperty-value"
    }
}

Expected Result

subproperty-value

Actual Result

expected "|" before filter, line:1, col:30, line:1, col:1
>> 1| {{ ["Key String with Spaces"].subproperty_key }}
      ^
ParseError: expected "|" before filter, line:1, col:30, line:1, col:1
    at ae.te [as constructor] (https://liquidjs.com/js/liquid.browser.min.js:1:5364)
    at new ae (https://liquidjs.com/js/liquid.browser.min.js:1:5755)
    at Nr.parseToken (https://liquidjs.com/js/liquid.browser.min.js:1:42812)
    at Nr.parseTokens (https://liquidjs.com/js/liquid.browser.min.js:1:42552)
    at Nr.parse (https://liquidjs.com/js/liquid.browser.min.js:1:42459)
    at P.parse (https://liquidjs.com/js/liquid.browser.min.js:1:72666)
    at P._parseAndRender (https://liquidjs.com/js/liquid.browser.min.js:1:73244)
    at P.<anonymous> (https://liquidjs.com/js/liquid.browser.min.js:1:73405)
    at Object.next (https://liquidjs.com/js/liquid.browser.min.js:1:2090)
    at https://liquidjs.com/js/liquid.browser.min.js:1:1136
From expected "|" before filter, line:1, col:30
>> 1| {{ ["Key String with Spaces"].subproperty_key }}
                                   ^
TokenizationError: expected "|" before filter, line:1, col:30
    at ie.te [as constructor] (https://liquidjs.com/js/liquid.browser.min.js:1:5364)
    at new ie (https://liquidjs.com/js/liquid.browser.min.js:1:5623)
    at F.error (https://liquidjs.com/js/liquid.browser.min.js:1:32131)
    at F.assert (https://liquidjs.com/js/liquid.browser.min.js:1:32232)
    at F.readFilter (https://liquidjs.com/js/liquid.browser.min.js:1:29186)
    at F.readFilters (https://liquidjs.com/js/liquid.browser.min.js:1:29053)
    at F.readFilteredValue (https://liquidjs.com/js/liquid.browser.min.js:1:28926)
    at new Fr (https://liquidjs.com/js/liquid.browser.min.js:1:39501)
    at Nr.parseToken (https://liquidjs.com/js/liquid.browser.min.js:1:42738)
    at Nr.parseTokens (https://liquidjs.com/js/liquid.browser.min.js:1:42552)
@harttle
Copy link
Owner

harttle commented Aug 19, 2023

Seems this works fine on shopify liquid. I'll treat this as a bug.

BTW, I noticed another problem: line:1, col:30, line:1, col:1 , it's output twice by different level of code.

@harttle harttle added the bug label Aug 19, 2023
@gtowne
Copy link
Author

gtowne commented Aug 21, 2023

Great, thanks for confirming! We have a workaround right now, but our workaround is a little ugly, so we'll be eagerly awaiting a fix. Let me know if there's anything more we can do to help with that.

github-actions bot pushed a commit that referenced this issue Aug 22, 2023
# [10.9.0](v10.8.4...v10.9.0) (2023-08-22)

### Bug Fixes

* case should allow multiple values separated by or ([b8e7e2d](b8e7e2d))
* for throws undefined var with a null value with strictVariables ([dc6a301](dc6a301))
* remove_last was eating an extra character ([fc27313](fc27313))

### Features

* more flexible squared property read expression, fixes [#643](#643) ([#646](#646)) ([660d9be](660d9be))
@github-actions
Copy link

🎉 This issue has been resolved in version 10.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@harttle
Copy link
Owner

harttle commented Aug 22, 2023

Try the latest version. I created a test case for this scenario:

it('#643 Error When Accessing Subproperty of Bracketed Reference', () => {
const engine = new Liquid()
const tpl = '{{ ["Key String with Spaces"].subpropertyKey }}'
const ctx = {
'Key String with Spaces': {
subpropertyKey: 'FOO'
}
}
expect(engine.parseAndRenderSync(tpl, ctx)).toEqual('FOO')
})

@gtowne
Copy link
Author

gtowne commented Aug 22, 2023

This looks like it resolves our issue! Thank you for such a quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants