Skip to content

Commit 98830e4

Browse files
authored
Unescaped comma in substitution should not be replaced during INI expansion (#2626)
Resolves #2616
1 parent 3661b94 commit 98830e4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

docs/changelog/2616.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unescaped comma in substitution should not be replaced during INI expansion - by :user:`gaborbernat`.

src/tox/config/loader/ini/replace.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def replace(conf: Config, loader: IniLoader, value: str, args: ConfigLoadArgs) -
5454

5555
REPLACE_PART = re.compile(
5656
r"""
57-
(?<! \\) { # Unescaped {
58-
( [^{}] | \\ { | \\ } )* # Anything except an unescaped { or }
57+
(?<!\\) { # Unescaped {
58+
( [^{},] | \\ { | \\ } )* # Anything except an unescaped { or }
5959
(?<! \\) } # Unescaped }
6060
|
6161
(?<! \\) \[ ] # Unescaped []
6262
""",
6363
re.VERBOSE,
64-
) # simplified - not verbose version (?<!\\)([^{}]|\\\{|\\\})*(?<!\\)\}|(?<!\\)\[\]
64+
)
6565

6666

6767
def find_replace_part(value: str, end: int) -> tuple[int, int, str | None]:
@@ -70,7 +70,8 @@ def find_replace_part(value: str, end: int) -> tuple[int, int, str | None]:
7070
return -1, -1, None
7171
if match.group() == "[]":
7272
return match.start(), match.end() - 1, "posargs" # brackets is an alias for positional arguments
73-
return match.start(), match.end() - 1, match.group()[1:-1]
73+
matched_part = match.group()[1:-1]
74+
return match.start(), match.end() - 1, matched_part
7475

7576

7677
def _replace_match(conf: Config, loader: IniLoader, value: str, conf_args: ConfigLoadArgs) -> str | None:

tests/config/loader/ini/test_factor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def test_factor_config(tox_ini_conf: ToxIniCreator) -> None:
136136
assert "Django>=1.6,<1.7" in deps
137137

138138

139+
def test_factor_config_do_not_replace_unescaped_comma(tox_ini_conf: ToxIniCreator) -> None:
140+
config = tox_ini_conf("[tox]\nenv_list = py37-{base,i18n},b")
141+
assert list(config) == ["py37-base", "py37-i18n", "b"]
142+
143+
139144
def test_factor_config_no_env_list_creates_env(tox_ini_conf: ToxIniCreator) -> None:
140145
"""If we have a factor that is not specified within the core env-list then that's also an environment"""
141146
config = tox_ini_conf(

0 commit comments

Comments
 (0)