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)