Skip to content

#215 backlash error#216

Open
Weisl wants to merge 7 commits intomasterfrom
#211-backlash-error
Open

#215 backlash error#216
Weisl wants to merge 7 commits intomasterfrom
#211-backlash-error

Conversation

@Weisl
Copy link
Owner

@Weisl Weisl commented Mar 11, 2026

Problem
Renaming objects would intermittently crash with:

re.error: bad escape \T at position 13
This happened because re.sub() treats its replacement string as a template where backslashes carry special meaning (\1 = group 1, \n = newline, etc.). If any replacement value contained a backslash followed by a letter — e.g. a Windows file path from @f, or a user-defined string variable — Python's regex engine would raise an error rather than insert the text literally. This only affected certain objects/scenes because the crash depended on what the variable values resolved to at runtime.

Changes
variable_replacer/variable_replacer.py
All re.sub() calls in replaceInputString now pass the replacement as a lambda callable instead of a bare string. When re.sub receives a callable, it calls it with the match object and uses the return value verbatim — no template processing, no backslash interpretation. This is the root cause fix.

operators/search_replace.py

Non-regex, case-insensitive path: same lambda fix applied to replaceSearch.sub(...).
Regex mode path: replaced the bare re.sub(searchReplaced, replaceReplaced, ...) call with explicit re.compile + pattern.sub, wrapped in try/except re.error blocks. Invalid regex patterns or replacement strings now surface a proper error popup instead of a raw traceback. The regex mode replacement is intentionally kept as a string (not a lambda) so users can still use backreferences like \1 in their regex replacements.
operators/search_select.py
The case-insensitive re.search call is now wrapped in try/except re.error, so an invalid search expression shows an error popup instead of crashing.

@Weisl Weisl added this to the 2.1.5 milestone Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant