Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading