fast-path simple if truthiness: use byte scanner before SIMPLE_CONDITION regex

This commit is contained in:
Tobi Lutke
2026-04-04 17:42:32 -07:00
committed by Chris Pak
parent f879183a23
commit 9d16eb3d05
+5
View File
@@ -89,6 +89,11 @@ module Liquid
SIMPLE_CONDITION = /\A\s*(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?\s*\z/o
def lax_parse(markup)
# Fastest path: simple identifier truthiness like "product.available" or "forloop.first"
if (simple = Variable.simple_variable_markup(markup))
return Condition.new(parse_expression(simple))
end
# Fast path: simple condition without and/or
if !markup.include?(' and ') && !markup.include?(' or ') && markup =~ SIMPLE_CONDITION
return Condition.new(