Avoid an expression match on a dynamic variable#61
Merged
Conversation
for compatibility with `empty` and `blank` expression literals resolving to an empty string, which shouldn't then be looked up again as a literl since there is an empty string literal.
macournoyer
approved these changes
Sep 28, 2020
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Shopify/liquid#1300 introduced an error in liquid-c's unit tests:
Which is basically saying that
[blank]is being parsed as having anilexpression instead of being the expected variable lookup for a blank string.The problem is that an
Expression::LITERALSlookup was being done twice on a square bracket variable lookup in liquid-c, once on the expression inside the square brackets (blank) and another time on the resulting expression. Only the former is done by the liquid gem (inExpression.parse).Shopify/liquid#1300 caused this test to fail because there is an Expression::LITERALS mapping
"blank" => ""and another mapping"" => nil. Previously, the first lookup would return aMethodLiteralobject, which there wasn't a second mapping for inExpression::LITERALS.Note that the assign tag doesn't even allow a variable to be assigned with an empty string for a name, it requires at least one character for the name.
Solution
Use a boolean flag to make sure we are only doing this
Expression::LITERALSlookup when we haven't just parsed square brackets around the variable name.Note that #60 will remove parse_variable method, which is why I wasn't seeing the failure when testing on that liquid-c branch.