Skip to content

Commit

Permalink
Allow escaping of {} in defaults (tox-dev#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Oct 18, 2020
1 parent 6a59be5 commit f0d8ae2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Jake Windle
Jannis Leidel
Joachim Brandon LeBlanc
Johannes Christ
John Mark Vandenberg
Jon Dufresne
Josh Smeaton
Josh Snyder
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1502.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow \{ and \} in default of {env:key:default}. - by :user:`jayvdb`
2 changes: 1 addition & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ class Replacer:
(?<!\\)[{]
(?:(?P<sub_type>[^[:{}]+):)? # optional sub_type for special rules
(?P<substitution_value>(?:\[[^,{}]*\])?[^:,{}]*) # substitution key
(?::(?P<default_value>[^{}]*))? # default value
(?::(?P<default_value>([^{}]|\\{|\\})*))? # default value
[}]
""",
re.VERBOSE,
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,17 @@ def test_command_env_substitution_global(self, newconfig):
envconfig = config.envconfigs["python"]
assert envconfig.commands == [["echo", "bar"]]

def test_command_env_substitution_default_escape(self, newconfig):
"""Ensure literal { and } in default of {env:key:default} values."""
config = newconfig(
r"""
[testenv]
commands = echo {env:FOO:\{bar\}}
""",
)
envconfig = config.envconfigs["python"]
assert envconfig.commands == [["echo", "{bar}"]]

def test_regression_issue595(self, newconfig):
config = newconfig(
"""
Expand Down

0 comments on commit f0d8ae2

Please sign in to comment.