Insert literal replacement text verbatim when use_regex is off (review SE-2)

re.sub always parses the replacement as a template, so a backslash in
the replacement (e.g. C:\1) raised PatternError even in literal mode.
Also drop an unused import and align js import paths with the
documented two-level extension path. Bump to 2.0.13.
This commit is contained in:
BRADSEC
2026-07-03 10:52:03 +10:00
parent 29d6e99dc2
commit 67b5a0e37f
5 changed files with 21 additions and 6 deletions
+4 -1
View File
@@ -95,7 +95,10 @@ class StringMultiReplaceNode:
f"StringMultiReplace: invalid regex for search '{search_str}': {e}. "
f"Disable use_regex to treat search strings as literal text."
)
result = regex.sub(replace_str, result)
# re.sub always parses the replacement as a template (\1, \g<>);
# in literal mode insert the user's text verbatim instead.
replacement = replace_str if use_regex else replace_str.replace("\\", "\\\\")
result = regex.sub(replacement, result)
if remove_extra_spaces:
result = self.cleanup_text(result)