mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 00:52:16 +00:00
Prevent backreferences from breaking regex.transform().
This commit is contained in:
@@ -38,7 +38,16 @@ def replace(s, pattern, replacement):
|
||||
pattern (str): the search expression
|
||||
replacement (str): the string to replace each match with
|
||||
"""
|
||||
return re.sub(pattern, replacement, s)
|
||||
# the replacement string may contain invalid backreferences (like \1 or \g)
|
||||
# which will cause python's regex to blow up. Since this should emulate
|
||||
# the jam version exactly and the jam version didn't support
|
||||
# backreferences, this version shouldn't either. re.sub
|
||||
# allows replacement to be a callable; this is being used
|
||||
# to simply return the replacement string and avoid the hassle
|
||||
# of worrying about backreferences within the string.
|
||||
def _replacement(matchobj):
|
||||
return replacement
|
||||
return re.sub(pattern, _replacement, s)
|
||||
|
||||
|
||||
@bjam_signature((['items', '*'], ['match'], ['replacement']))
|
||||
|
||||
Reference in New Issue
Block a user