From 19a552f1e0eadec5c5f0cb5e3deea86a190926be Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Fri, 27 Aug 2021 22:57:07 +0200 Subject: [PATCH 1/2] 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 --- src/tox/config/loader/ini/replace.py | 2 +- tests/config/loader/ini/replace/test_replace_env_var.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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" From 1cc93d2c0d2187b09da51265434b1f1426588ad7 Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Sat, 28 Aug 2021 00:13:11 +0200 Subject: [PATCH 2/2] Add changelog entry --- docs/changelog/2182.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changelog/2182.bugfix.rst 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`.