Skip to content

Commit

Permalink
fix parsing UTF-8 multi byte string expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 8, 2024
1 parent abe3dec commit 10ef505
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ class Expression2
RANGES_REGEX = /\A\(\s*(?>(\S+)\s*\.\.)\s*(\S+)\s*\)\z/

def self.parse(markup)
return nil unless markup
return unless markup

markup = markup.strip # markup can be a frozen string

return if markup.length == 0

if (markup.start_with?('"') && markup.end_with?('"')) ||
(markup.start_with?("'") && markup.end_with?("'"))
return markup.byteslice(1, markup.length - 2)
return markup[1..-2]
elsif (markup.start_with?("(") && markup.end_with?(")")) && markup =~ RANGES_REGEX
return RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2))
end
Expand Down
1 change: 1 addition & 0 deletions test/integration/expression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_string
assert_template_result("double quoted", '{{"double quoted"}}')
assert_template_result("spaced", "{{ 'spaced' }}")
assert_template_result("spaced2", "{{ 'spaced2' }}")
assert_template_result("emoji🔥", "{{ 'emoji🔥' }}")
end

def test_int
Expand Down

0 comments on commit 10ef505

Please sign in to comment.