From 4896d6d497e88eaaae83c78d048b90707d5150ef Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:40:47 -0400 Subject: [PATCH] =?UTF-8?q?Replace=20manual=20scan=5Fcomparison=5Fop=20wit?= =?UTF-8?q?h=20regex=20=E2=80=94=20cleaner=20and=20avoids=20byteslice=20al?= =?UTF-8?q?location=20for=20op=20strings\n\nResult:=20{"status":"keep","co?= =?UTF-8?q?mbined=5F=C2=B5s":4007,"parse=5F=C2=B5s":2808,"render=5F=C2=B5s?= =?UTF-8?q?":1199,"allocations":25535}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/cursor.rb | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/liquid/cursor.rb b/lib/liquid/cursor.rb index 71e19ccb..acd39444 100644 --- a/lib/liquid/cursor.rb +++ b/lib/liquid/cursor.rb @@ -212,27 +212,13 @@ module Liquid }.freeze # Scan a comparison operator. Returns frozen string or nil. - def scan_comparison_op - start = @ss.pos - b = @ss.peek_byte - case b - when 61, 33, 60, 62 # = ! < > - @ss.scan_byte - b2 = @ss.peek_byte - if b2 == 61 || b2 == 62 # second char of ==, !=, <=, >=, <> - @ss.scan_byte - end - when 99 # 'c' for contains - id = scan_id - return unless id == "contains" + # Regex for comparison operators + COMPARISON_OP_REGEX = /==|!=|<>|<=|>=|<|>|contains(?!\w)/ - return COMPARISON_OPS['contains'] - else - return + def scan_comparison_op + if (op = @ss.scan(COMPARISON_OP_REGEX)) + COMPARISON_OPS[op] end - op_str = @source.byteslice(start, @ss.pos - start) - COMPARISON_OPS[op_str] || (@ss.pos = start - nil) end # ── Tag parsing helpers ─────────────────────────────────────────