From ea3ec1f27b24f6bcb55fdeb9047a6488c07e8233 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 04:23:05 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20regex=20replacem?= =?UTF-8?q?ent=20in=20template=20init=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/init.py b/scripts/init.py index 06a0290..32f9b17 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -134,8 +134,9 @@ def update_file(filepath: str, file_replacements: list[tuple[re.Pattern, str]]): return new_content = content for pattern, replacement in file_replacements: - # Use a lambda for replacement to avoid regex backreference injection - new_content = pattern.sub(lambda _, r=replacement: r, new_content) + # Performance Optimization: Escape backslashes in replacement string so re.sub handles + # it directly in C without invoking a Python lambda function per match or risking Ruff B023. + new_content = pattern.sub(replacement.replace("\\", "\\\\"), new_content) if new_content != content: path.write_text(new_content)