Use an atomic subgroup in range regex to avoid pathological backtracking (#1360)

This commit is contained in:
Dylan Thacker-Smith
2020-11-16 10:29:36 -05:00
committed by GitHub
parent 300adfd7ae
commit 1850511334
+4 -1
View File
@@ -14,7 +14,10 @@ module Liquid
DOUBLE_QUOTED_STRING = /\A\s*"(.*)"\s*\z/m
INTEGERS_REGEX = /\A\s*(-?\d+)\s*\z/
FLOATS_REGEX = /\A\s*(-?\d[\d\.]+)\s*\z/
RANGES_REGEX = /\A\s*\(\s*(\S+)\s*\.\.\s*(\S+)\s*\)\s*\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+)\s*\)\s*\z/
def self.parse(markup)
case markup