From 58777bcd930b1f4285a3d3ce879310dfd4b2e36b Mon Sep 17 00:00:00 2001 From: Michael Go Date: Mon, 13 Jan 2025 17:13:27 -0400 Subject: [PATCH 1/2] float has to start with a digit --- lib/liquid/expression.rb | 11 +++++++++-- test/integration/expression_test.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/liquid/expression.rb b/lib/liquid/expression.rb index f2abb2fc1..979c34571 100644 --- a/lib/liquid/expression.rb +++ b/lib/liquid/expression.rb @@ -79,10 +79,17 @@ def parse_number(markup, ss) end 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 - 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 first_dot_pos = nil diff --git a/test/integration/expression_test.rb b/test/integration/expression_test.rb index 0eef5dc9d..29e456321 100644 --- a/test/integration/expression_test.rb +++ b/test/integration/expression_test.rb @@ -26,7 +26,16 @@ def test_int def test_float assert_template_result("-17.42", "{{ -17.42 }}") 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") + + # 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 def test_range From 0639a094a8fb007d20a2a65f86163708df9eea89 Mon Sep 17 00:00:00 2001 From: Michael Go Date: Mon, 13 Jan 2025 17:16:33 -0400 Subject: [PATCH 2/2] bump version to 5.6.2 --- lib/liquid/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid/version.rb b/lib/liquid/version.rb index 7c3004e50..ab7d74083 100644 --- a/lib/liquid/version.rb +++ b/lib/liquid/version.rb @@ -2,5 +2,5 @@ # frozen_string_literal: true module Liquid - VERSION = "5.6.1" + VERSION = "5.6.2" end