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 lookup on variable with literal name #98

Merged
merged 1 commit into from
Oct 21, 2020

Conversation

dylanahsmith
Copy link
Contributor

Problem

#60 introduced a subtle regression for doing a lookup on a variable with a name that matches a literal.

For example,

Liquid::Template.parse("{{ blank.svg | asset_url }}", error_mode: :strict)

would result in the following error after that pull request was introduced

Liquid::SyntaxError (Liquid syntax error: Expected end_of_string but found dot in "{{ blank.svg | asset_url }}")

but we would get the strict parse error on the commit before that PR was merged or when just using the liquid gem.

This quirk comes from the LITERALS.key?(markup) check being used to detect if the markup is for a literal. If that literal name is followed by an object lookup (e.g. .svg) then it is handled by VariableLookup which will treat the literal name (e.g. blank) as the variable name.

Solution

Lookahead to make sure the identifier isn't followed by a . or [ token before treating it as a literal.

@dylanahsmith dylanahsmith merged commit 65e4f1f into master Oct 21, 2020
@dylanahsmith dylanahsmith deleted the literal-var-name-lookup branch October 21, 2020 20:28
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