remove Expression2 strscan workaround

This commit is contained in:
Michael Go
2025-01-10 14:23:57 -04:00
parent 7c9b77e8cf
commit 97cada61f9
4 changed files with 11 additions and 169 deletions
+1 -49
View File
@@ -3,52 +3,7 @@
require "lru_redux"
module Liquid
class Expression1
LITERALS = {
nil => nil,
'nil' => nil,
'null' => nil,
'' => nil,
'true' => true,
'false' => false,
'blank' => '',
'empty' => ''
}.freeze
INTEGERS_REGEX = /\A(-?\d+)\z/
FLOATS_REGEX = /\A(-?\d[\d\.]+)\z/
# Use an atomic group (?>...) to avoid pathological backtracing from
# malicious input as described in https://github.com/Shopify/liquid/issues/1357
RANGES_REGEX = /\A\(\s*(?>(\S+)\s*\.\.)\s*(\S+)\s*\)\z/
def self.parse(markup, _ss = nil, _cache = nil)
return nil unless markup
markup = markup.strip
if (markup.start_with?('"') && markup.end_with?('"')) ||
(markup.start_with?("'") && markup.end_with?("'"))
return markup[1..-2]
end
case markup
when INTEGERS_REGEX
Regexp.last_match(1).to_i
when RANGES_REGEX
RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2), nil)
when FLOATS_REGEX
Regexp.last_match(1).to_f
else
if LITERALS.key?(markup)
LITERALS[markup]
else
VariableLookup.parse(markup, nil)
end
end
end
end
class Expression2
class Expression
LITERALS = {
nil => nil,
'nil' => nil,
@@ -161,7 +116,4 @@ module Liquid
end
end
end
# Remove this once we can depend on strscan >= 3.1.1
Expression = HAS_STRING_SCANNER_SCAN_BYTE ? Expression2 : Expression1
end