Skip to content

Commit

Permalink
replace: treat single backslash replacement as literal
Browse files Browse the repository at this point in the history
if the replaced value is a single backslash, then process replace on the
left and right parts of the value separately so that the replacement
cannot act as an escape in other parts of the value.

Fixes tox-dev#2732
  • Loading branch information
masenf committed Dec 17, 2022
1 parent ae1ff98 commit 68087ae
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tox/config/loader/ini/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def replace(conf: Config, loader: IniLoader, value: str, args: ConfigLoadArgs) -
# want to enforce escaping curly braces, e.g. it should work to write: env_list = {py39,py38}-{,dep}
end = end + 1
continue
elif replaced == "\\":
# a replaced backslash should NOT affect subsequent iterations, so recurse on left and right
return replaced.join(replace(conf, loader, vp, args) for vp in [value[:start], value[end + 1 :]])
new_value = f"{value[:start]}{replaced}{value[end + 1:]}"
end = 0 # if we performed a replacement start over
if new_value == value: # if we're not making progress stop (circular reference?)
Expand Down

0 comments on commit 68087ae

Please sign in to comment.