-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow variable and tag end characters to be quoted. #624
base: main
Are you sure you want to change the base?
Conversation
Can you benchmark the performance impact of this? |
@@ -35,7 +35,8 @@ module Liquid | |||
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o | |||
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o | |||
AnyStartingTag = /\{\{|\{\%/ | |||
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om | |||
tag_contents = /(?:#{QuotedString}|.)*?/m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm this being a local variable and not a constant looks kinda odd...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding [^"'}]+|
before QuotedString would reduce the number of backtracks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should only be backtracking for unterminated quotes the way it is, which is an edge case rather than a common case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, the local variable is because I don't want it to be used outside of liquid
👍 |
@dylanahsmith: Were you still planning to ship this? |
We need to make it easier to test the impact of possibly breaking changes on existing templates, since that is what is blocking changes like this from happening. This is the problem having a language that isn't strict, it doesn't leave room for extension without possibly breaking existing code. |
@pushrax and @trishume for review
cc @knu
Closes #623
Depends on Shopify/liquid-c#27
Problem
Add support for quoting string string in variables and tags to contain end variable and tag characters.
Solution
When encountering a quote character inside a variable or tag, the tokenizer will include everything up to the end quote character (if one is present) even if it includes the tag/variable end characters.
I tried to keep the tag contents regex as simple as possible. I also added integration tests that fail without using the liquid-c without the same support for this case.