avoid setting up StringScanner for parsing simple numbers

This commit is contained in:
Michael Go
2025-01-07 14:32:46 -04:00
parent cef64e277e
commit 71506ad54e
+6 -6
View File
@@ -109,12 +109,6 @@ module Liquid
end
def parse_number(markup, ss)
ss.string = markup
# the first byte must be a digit, a period, or a dash
byte = ss.scan_byte
return false if byte != DASH && byte != DOT && (byte < ZERO || byte > NINE)
# check if the markup is simple integer or float
case markup
when INTEGER_REGEX
@@ -123,6 +117,12 @@ module Liquid
return markup.to_f
end
ss.string = markup
# the first byte must be a digit, a period, or a dash
byte = ss.scan_byte
return false if byte != DASH && byte != DOT && (byte < ZERO || byte > NINE)
# The markup could be a float with multiple dots
first_dot_pos = nil
num_end_pos = nil