From 6c13805a608936c0be80acdea9b4612c2219777b Mon Sep 17 00:00:00 2001 From: Michael Go Date: Mon, 28 Oct 2024 17:33:55 -0300 Subject: [PATCH] fix parsing Variable blockbody with multibyte character --- lib/liquid/block_body.rb | 2 +- test/unit/block_unit_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 816c2bc6..e4ada7d1 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -252,7 +252,7 @@ module Liquid parse_end = token.length - 3 parse_end -= 1 if token[parse_end] == "-" markup_end = parse_end - i + 1 - markup = markup_end <= 0 ? "" : token.byteslice(i, markup_end) + markup = markup_end <= 0 ? "" : token.slice(i, markup_end) return Variable.new(markup, parse_context) end diff --git a/test/unit/block_unit_test.rb b/test/unit/block_unit_test.rb index 81b79d85..f28c30e1 100644 --- a/test/unit/block_unit_test.rb +++ b/test/unit/block_unit_test.rb @@ -32,6 +32,12 @@ class BlockUnitTest < Minitest::Test assert_equal(String, template.root.nodelist[2].class) end + def test_variable_with_multibyte_character + template = Liquid::Template.parse("{{ '❤️' }}") + assert_equal(1, template.root.nodelist.size) + assert_equal(Variable, template.root.nodelist[0].class) + end + def test_variable_many_embedded_fragments template = Liquid::Template.parse(" {{funk}} {{so}} {{brother}} ") assert_equal(7, template.root.nodelist.size)