mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
float has to start with a digit
This commit is contained in:
@@ -79,10 +79,17 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
ss.string = markup
|
ss.string = markup
|
||||||
# the first byte must be a digit, a period, or a dash
|
# the first byte must be a digit or a dash
|
||||||
byte = ss.scan_byte
|
byte = ss.scan_byte
|
||||||
|
|
||||||
return false if byte != DASH && byte != DOT && (byte < ZERO || byte > NINE)
|
return false if byte != DASH && (byte < ZERO || byte > NINE)
|
||||||
|
|
||||||
|
if byte == DASH
|
||||||
|
peek_byte = ss.peek_byte
|
||||||
|
|
||||||
|
# if it starts with a dash, the next byte must be a digit
|
||||||
|
return false if peek_byte.nil? || !(peek_byte >= ZERO && peek_byte <= NINE)
|
||||||
|
end
|
||||||
|
|
||||||
# The markup could be a float with multiple dots
|
# The markup could be a float with multiple dots
|
||||||
first_dot_pos = nil
|
first_dot_pos = nil
|
||||||
|
|||||||
@@ -26,7 +26,16 @@ class ExpressionTest < Minitest::Test
|
|||||||
def test_float
|
def test_float
|
||||||
assert_template_result("-17.42", "{{ -17.42 }}")
|
assert_template_result("-17.42", "{{ -17.42 }}")
|
||||||
assert_template_result("2.5", "{{ 2.5 }}")
|
assert_template_result("2.5", "{{ 2.5 }}")
|
||||||
|
assert_expression_result(0.0, "0.....5")
|
||||||
|
assert_expression_result(0.0, "-0..1")
|
||||||
assert_expression_result(1.5, "1.5")
|
assert_expression_result(1.5, "1.5")
|
||||||
|
|
||||||
|
# this is a unfortunate quirky behavior of Liquid
|
||||||
|
result = Expression.parse(".5")
|
||||||
|
assert_kind_of(Liquid::VariableLookup, result)
|
||||||
|
|
||||||
|
result = Expression.parse("-.5")
|
||||||
|
assert_kind_of(Liquid::VariableLookup, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_range
|
def test_range
|
||||||
|
|||||||
Reference in New Issue
Block a user