Skip to content

Commit 0558bd1

Browse files
authoredJan 13, 2025
Merge pull request #1886 from Shopify/fix-parsing-float-with-leading-point
float has to start with a digit
2 parents 323951b + 0639a09 commit 0558bd1

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed
 

‎lib/liquid/expression.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ def parse_number(markup, ss)
7979
end
8080

8181
ss.string = markup
82-
# the first byte must be a digit, a period, or a dash
82+
# the first byte must be a digit or a dash
8383
byte = ss.scan_byte
8484

85-
return false if byte != DASH && byte != DOT && (byte < ZERO || byte > NINE)
85+
return false if byte != DASH && (byte < ZERO || byte > NINE)
86+
87+
if byte == DASH
88+
peek_byte = ss.peek_byte
89+
90+
# if it starts with a dash, the next byte must be a digit
91+
return false if peek_byte.nil? || !(peek_byte >= ZERO && peek_byte <= NINE)
92+
end
8693

8794
# The markup could be a float with multiple dots
8895
first_dot_pos = nil

‎lib/liquid/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# frozen_string_literal: true
33

44
module Liquid
5-
VERSION = "5.6.1"
5+
VERSION = "5.6.2"
66
end

‎test/integration/expression_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ def test_int
2626
def test_float
2727
assert_template_result("-17.42", "{{ -17.42 }}")
2828
assert_template_result("2.5", "{{ 2.5 }}")
29+
assert_expression_result(0.0, "0.....5")
30+
assert_expression_result(0.0, "-0..1")
2931
assert_expression_result(1.5, "1.5")
32+
33+
# this is a unfortunate quirky behavior of Liquid
34+
result = Expression.parse(".5")
35+
assert_kind_of(Liquid::VariableLookup, result)
36+
37+
result = Expression.parse("-.5")
38+
assert_kind_of(Liquid::VariableLookup, result)
3039
end
3140

3241
def test_range

0 commit comments

Comments
 (0)
Failed to load comments.