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