Skip to content

Commit 1810e2d

Browse files
jayvdbssbarnea
authored andcommitted
Allow escaping of {} in defaults (tox-dev#1696)
Fixes tox-dev#1502
1 parent 4541c51 commit 1810e2d

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Jake Windle
4848
Jannis Leidel
4949
Joachim Brandon LeBlanc
5050
Johannes Christ
51+
John Mark Vandenberg
5152
Jon Dufresne
5253
Josh Smeaton
5354
Josh Snyder

docs/changelog/1502.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow \{ and \} in default of {env:key:default}. - by :user:`jayvdb`

src/tox/config/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ class Replacer:
17311731
(?<!\\)[{]
17321732
(?:(?P<sub_type>[^[:{}]+):)? # optional sub_type for special rules
17331733
(?P<substitution_value>(?:\[[^,{}]*\])?[^:,{}]*) # substitution key
1734-
(?::(?P<default_value>[^{}]*))? # default value
1734+
(?::(?P<default_value>([^{}]|\\{|\\})*))? # default value
17351735
[}]
17361736
""",
17371737
re.VERBOSE,

tests/unit/config/test_config.py

+11
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,17 @@ def test_command_env_substitution_global(self, newconfig):
453453
envconfig = config.envconfigs["python"]
454454
assert envconfig.commands == [["echo", "bar"]]
455455

456+
def test_command_env_substitution_default_escape(self, newconfig):
457+
"""Ensure literal { and } in default of {env:key:default} values."""
458+
config = newconfig(
459+
r"""
460+
[testenv]
461+
commands = echo {env:FOO:\{bar\}}
462+
""",
463+
)
464+
envconfig = config.envconfigs["python"]
465+
assert envconfig.commands == [["echo", "{bar}"]]
466+
456467
def test_regression_issue595(self, newconfig):
457468
config = newconfig(
458469
"""

0 commit comments

Comments
 (0)