Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float has to start with a digit #1886

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# frozen_string_literal: true

module Liquid
VERSION = "5.6.1"
VERSION = "5.6.2"
end
9 changes: 9 additions & 0 deletions test/integration/expression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading