Skip to content

Fix lookup on variable with literal name#98

Merged
dylanahsmith merged 1 commit into
masterfrom
literal-var-name-lookup
Oct 21, 2020
Merged

Fix lookup on variable with literal name#98
dylanahsmith merged 1 commit into
masterfrom
literal-var-name-lookup

Conversation

@dylanahsmith
Copy link
Copy Markdown
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