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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user