Revert "Merge pull request #325 from Shopify/remove-variable-incomplete-end"

That pull request broke raw tags with open variable tags. E.g.

{% raw %}
{{
{% endraw %}
{{ 1 }}

This reverts commit fbaabf3b59, reversing
changes made to af24d2c2ab.
This commit is contained in:
Dylan Thacker-Smith
2014-03-24 09:56:56 -04:00
parent d1bfda15e3
commit fdf03076e0
5 changed files with 18 additions and 24 deletions

View File

@@ -3,8 +3,6 @@
## 3.0.0 / not yet released / branch "master"
* ...
* Make tag/variable termination error clearer, see #325 [Dylan Thacker-Smith, dylanahsmith]
* Allow quoted single curly braces in variables, see #325 [Dylan Thacker-Smith, dylanahsmith]
* Allow newlines in tags and variables, see #324 [Dylan Thacker-Smith, dylanahsmith]
* Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith, dylanahsmith]
* Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev, bogdan]

View File

@@ -24,17 +24,18 @@ module Liquid
ArgumentSeparator = ','
FilterArgumentSeparator = ':'
VariableAttributeSeparator = '.'
TagStart = '{%'
TagEnd = '%}'
TagStart = /\{\%/
TagEnd = /\%\}/
VariableSignature = /\(?[\w\-\.\[\]]\)?/
VariableSegment = /[\w\-]/
VariableStart = '{{'
VariableEnd = '}}'
VariableStart = /\{\{/
VariableEnd = /\}\}/
VariableIncompleteEnd = /\}\}?/
QuotedString = /"[^"]*"|'[^']*'/
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
AnyStartingTag = /\{\{|\{\%/
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableEnd}/om
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
end

View File

@@ -3,6 +3,7 @@ module Liquid
IsTag = /\A#{TagStart}/o
IsVariable = /\A#{VariableStart}/o
FullToken = /\A#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
ContentOfVariable = /\A#{VariableStart}(.*)#{VariableEnd}\z/om
def blank?
@blank || false
@@ -40,14 +41,10 @@ module Liquid
unknown_tag($1, $2, tokens)
end
else
raise_tag_termination_error("errors.syntax.tag_termination", token + tokens.shift.to_s, TagEnd)
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination", :token => token, :tag_end => TagEnd.inspect))
end
when IsVariable
if token.size < 4
raise_tag_termination_error("errors.syntax.variable_termination", token + tokens.shift.to_s, VariableEnd)
end
markup = token[2...-2]
new_var = Variable.new(markup, @options)
new_var = create_variable(token)
@nodelist << new_var
@children << new_var
@blank = false
@@ -102,6 +99,13 @@ module Liquid
@tag_name
end
def create_variable(token)
token.scan(ContentOfVariable) do |content|
return Variable.new(content.first, @options)
end
raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination", :token => token, :tag_end => VariableEnd.inspect))
end
def render(context)
render_all(@nodelist, context)
end
@@ -112,11 +116,6 @@ module Liquid
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_never_closed", :block_name => block_name))
end
def raise_tag_termination_error(error_name, token, tag_end)
token = token.size > 50 ? "'#{token[0...47]}'..." : "'#{token}'"
raise SyntaxError.new(options[:locale].t(error_name, :token => token, :tag_end => tag_end))
end
def render_all(list, context)
output = []
context.resource_limits[:render_length_current] = 0

View File

@@ -15,8 +15,8 @@
unknown_tag: "Unknown tag '%{tag}'"
invalid_delimiter: "'end' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
unexpected_else: "%{block_name} tag does not expect else tag"
tag_termination: "Tag %{token} was not properly terminated with '%{tag_end}'"
variable_termination: "Variable %{token} was not properly terminated with '%{tag_end}'"
tag_termination: "Tag '%{token}' was not properly terminated with regexp: %{tag_end}"
variable_termination: "Variable '%{token}' was not properly terminated with regexp: %{tag_end}"
tag_never_closed: "'%{block_name}' tag was never closed"
meta_syntax_error: "Liquid syntax error: #{e.message}"
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"

View File

@@ -201,8 +201,4 @@ class VariableResolutionTest < Test::Unit::TestCase
def test_multiline_variable
assert_equal 'worked', Template.parse("{{\ntest\n}}").render!('test' => 'worked')
end
def test_quoted_single_curly_braces
assert_template_result "{user}", "{{ variable | prepend: '{' | append: '}' }}", 'variable' => 'user'
end
end # VariableTest