From 3682414cc442cff4f449cea16e5e5064c2772451 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 21 Mar 2014 00:21:51 -0400 Subject: [PATCH] Allow quoted single curly braces in variables. --- History.md | 1 + lib/liquid.rb | 3 +-- test/liquid/variable_test.rb | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 69d4bd31..2e2af016 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,7 @@ ## 3.0.0 / not yet released / branch "master" * ... +* 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] diff --git a/lib/liquid.rb b/lib/liquid.rb index 257efc69..41768812 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -30,7 +30,6 @@ module Liquid VariableSegment = /[\w\-]/ VariableStart = /\{\{/ VariableEnd = /\}\}/ - VariableIncompleteEnd = /\}\}?/ QuotedString = /"[^"]*"|'[^']*'/ QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s|:,]+/ @@ -40,7 +39,7 @@ module Liquid Expression = /(?:#{QuotedFragment}(?:#{SpacelessFilter})*)/o TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o AnyStartingTag = /\{\{|\{\%/ - PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om + PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableEnd}/om TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o end diff --git a/test/liquid/variable_test.rb b/test/liquid/variable_test.rb index 00210df8..3bd5c42b 100644 --- a/test/liquid/variable_test.rb +++ b/test/liquid/variable_test.rb @@ -201,4 +201,8 @@ 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