From 4a12fee1f5c5dc441e7c77bb08c543802031d18f Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Mon, 13 Jul 2015 13:19:56 -0400 Subject: [PATCH 1/2] Allow variable and tag end characters to be quoted. --- lib/liquid.rb | 3 ++- test/integration/tags/assign_tag_test.rb | 13 +++++++++++++ test/integration/variable_test.rb | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/integration/tags/assign_tag_test.rb diff --git a/lib/liquid.rb b/lib/liquid.rb index f4c6fea2f..dd33dce52 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -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 + PartialTemplateParser = /#{TagStart}#{tag_contents}#{TagEnd}|#{VariableStart}#{tag_contents}#{VariableIncompleteEnd}/om TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o diff --git a/test/integration/tags/assign_tag_test.rb b/test/integration/tags/assign_tag_test.rb new file mode 100644 index 000000000..9796dafab --- /dev/null +++ b/test/integration/tags/assign_tag_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class AssignTagTest < Minitest::Test + include Liquid + + def test_assign + assert_template_result('monkey', "{% assign foo = 'monkey' %}{{ foo }}") + end + + def test_string_with_end_tag + assert_template_result("{% quoted %}", "{% assign string = '{% quoted %}' %}{{ string }}") + end +end diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 58df83385..cf4cf949e 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -89,4 +89,9 @@ def test_hash_with_default_proc def test_multiline_variable assert_equal 'worked', Template.parse("{{\ntest\n}}").render!('test' => 'worked') end + + def test_string_with_curly_brackets + json = '{ "key": { "nested": "value" }}' + assert_template_result(json, "{{ '#{json}' }}") + end end From 6a9a7ae8d298d75b8d1bb19b27ebfafcfe6da1e7 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Mon, 13 Jul 2015 22:03:16 -0400 Subject: [PATCH 2/2] Use tokenizer-quoted-strings liquid-c branch. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c10cabc7e..c8483999d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,6 @@ group :test do gem 'rubocop', '>=0.32.0' platform :mri do - gem 'liquid-c', github: 'Shopify/liquid-c', ref: '2570693d8d03faa0df9160ec74348a7149436df3' + gem 'liquid-c', github: 'Shopify/liquid-c', ref: '11d38237d9f491588a58c83dc3d364a7d0d1d55b' end end