mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
fast-path simple if truthiness: use byte scanner before SIMPLE_CONDITION regex
This commit is contained in:
@@ -89,6 +89,11 @@ module Liquid
|
|||||||
SIMPLE_CONDITION = /\A\s*(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?\s*\z/o
|
SIMPLE_CONDITION = /\A\s*(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?\s*\z/o
|
||||||
|
|
||||||
def lax_parse(markup)
|
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
|
# Fast path: simple condition without and/or
|
||||||
if !markup.include?(' and ') && !markup.include?(' or ') && markup =~ SIMPLE_CONDITION
|
if !markup.include?(' and ') && !markup.include?(' or ') && markup =~ SIMPLE_CONDITION
|
||||||
return Condition.new(
|
return Condition.new(
|
||||||
|
|||||||
Reference in New Issue
Block a user