diff --git a/docs/changelog/2182.bugfix.rst b/docs/changelog/2182.bugfix.rst new file mode 100644 index 000000000..a78577254 --- /dev/null +++ b/docs/changelog/2182.bugfix.rst @@ -0,0 +1 @@ +Fix env variable substitutions with defaults containing colon (e.g. URL) -- by :user:`comabrewer`. diff --git a/src/tox/config/loader/ini/replace.py b/src/tox/config/loader/ini/replace.py index ca8c4a32c..b2735c582 100644 --- a/src/tox/config/loader/ini/replace.py +++ b/src/tox/config/loader/ini/replace.py @@ -207,7 +207,7 @@ def replace_env(conf: "Config", env_name: Optional[str], args: List[str], chain: if key in os.environ: return os.environ[key] - return "" if len(args) == 1 else args[1] + return "" if len(args) == 1 else ":".join(args[1:]) def replace_tty(args: List[str]) -> str: diff --git a/tests/config/loader/ini/replace/test_replace_env_var.py b/tests/config/loader/ini/replace/test_replace_env_var.py index 3a298d79c..1ce8fc1c4 100644 --- a/tests/config/loader/ini/replace/test_replace_env_var.py +++ b/tests/config/loader/ini/replace/test_replace_env_var.py @@ -36,3 +36,10 @@ def test_replace_env_var_circular(replace_one: ReplaceOne, monkeypatch: MonkeyPa monkeypatch.setenv("MAGIC", "{env:MAGIC}") result = replace_one("{env:MAGIC}") assert result == "{env:MAGIC}" + + +def test_replace_env_default_with_colon(replace_one: ReplaceOne, monkeypatch: MonkeyPatch) -> None: + """If we have a factor that is not specified within the core env-list then that's also an environment""" + monkeypatch.delenv("MAGIC", raising=False) + result = replace_one("{env:MAGIC:https://some.url.org}") + assert result == "https://some.url.org"