Skip to content

Commit

Permalink
Merge pull request #1835 from Shopify/fix-multibyte-variable-parsing
Browse files Browse the repository at this point in the history
fix parsing Variable blockbody with multibyte character
  • Loading branch information
ggmichaelgo authored Oct 28, 2024
2 parents 36251e6 + 6c13805 commit 1943441
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/liquid/block_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_variable(token, parse_context)
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
Expand Down
6 changes: 6 additions & 0 deletions test/unit/block_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def test_variable_middle
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)
Expand Down

0 comments on commit 1943441

Please sign in to comment.