Skip to content

Commit

Permalink
Fix substitude regex replacement
Browse files Browse the repository at this point in the history
The python re.sub function supports backslash escapes (like \6 or \g<2>) in the replacement. 
Therefore every backslash in replace_in_string function needs to be escaped. 
Note: This only happens on Windows due to its path separator.
  • Loading branch information
oechslein authored Sep 24, 2019
1 parent 2126eb0 commit ce3d6c5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pykg_config/substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def substitute(value, replacements, globals={}):
def replace_in_string(value, name, substitution):
# Replace all instances of name in value with substitution
to_replace = get_to_replace_re(name)
# Make sure backslashes are escaped (e.g. '\g' or '\0', ... are escaped)
substitution = substitution.replace('\\', '\\\\')
return to_replace.sub(substitution, value)


Expand Down

0 comments on commit ce3d6c5

Please sign in to comment.