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

Allow variable and tag end characters to be quoted. #624

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dylanahsmith
Copy link
Contributor

@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.

@fw42
Copy link
Contributor

fw42 commented Jul 14, 2015

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
Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@trishume
Copy link
Contributor

👍
Again would be great if we could run a breakage test job.

@fw42
Copy link
Contributor

fw42 commented Jan 13, 2016

@dylanahsmith: Were you still planning to ship this?

@dylanahsmith
Copy link
Contributor Author

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.

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.

5 participants