Skip to content

Commit eac98db

Browse files
authored
Fix env variable substitutions with defaults containing colon (#2186)
* Fix handling of substitution defaults containing colon * Join remaining parts of string instead of splitting on colon. * Add test with substitution default that contains a colon (URL). Fixes #2182 Signed-off-by: Marco Weber <[email protected]> * Add changelog entry
1 parent 6f8ba7f commit eac98db

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/changelog/2182.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix env variable substitutions with defaults containing colon (e.g. URL) -- by :user:`comabrewer`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def replace_env(conf: "Config", env_name: Optional[str], args: List[str], chain:
207207
if key in os.environ:
208208
return os.environ[key]
209209

210-
return "" if len(args) == 1 else args[1]
210+
return "" if len(args) == 1 else ":".join(args[1:])
211211

212212

213213
def replace_tty(args: List[str]) -> str:

tests/config/loader/ini/replace/test_replace_env_var.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ def test_replace_env_var_circular(replace_one: ReplaceOne, monkeypatch: MonkeyPa
3636
monkeypatch.setenv("MAGIC", "{env:MAGIC}")
3737
result = replace_one("{env:MAGIC}")
3838
assert result == "{env:MAGIC}"
39+
40+
41+
def test_replace_env_default_with_colon(replace_one: ReplaceOne, monkeypatch: MonkeyPatch) -> None:
42+
"""If we have a factor that is not specified within the core env-list then that's also an environment"""
43+
monkeypatch.delenv("MAGIC", raising=False)
44+
result = replace_one("{env:MAGIC:https://some.url.org}")
45+
assert result == "https://some.url.org"

0 commit comments

Comments
 (0)