fix: Don't encode URLs for `mamba env export --explicit` (#3745)

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
This commit is contained in:
Ben Mares 2025-01-27 05:35:12 -08:00 committed by GitHub
parent 5a76102995
commit c1c9f5fc90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 2 deletions

View File

@ -293,6 +293,22 @@ namespace
REQUIRE(url.host(URL::Decode::no) != "mamba%f0%9f%86%92%f0%9f%94%ac.org");
}
SECTION("https://conda.anaconda.org/conda-forge/linux-64/x264-1!164.3095-h166bdaf_2.tar.bz2")
{
// Non-regression test for: https://github.com/mamba-org/mamba/issues/3737
// Check that the `!` character is not encoded
const URL url = URL::parse(
"https://conda.anaconda.org/conda-forge/linux-64/x264-1!164.3095-h166bdaf_2.tar.bz2"
)
.value();
REQUIRE(
url.path(URL::Decode::no) == "/conda-forge/linux-64/x264-1!164.3095-h166bdaf_2.tar.bz2"
);
REQUIRE(
url.path(URL::Decode::yes) == "/conda-forge/linux-64/x264-1!164.3095-h166bdaf_2.tar.bz2"
);
}
SECTION("file://C:/Users/wolfv/test/document.json")
{
if (on_win)

View File

@ -157,8 +157,11 @@ set_env_command(CLI::App* com, Configuration& config)
.transform(
[](specs::CondaURL&& url)
{
using Credentials = typename specs::CondaURL::Credentials;
return url.str(Credentials::Remove);
return url.pretty_str(
specs::CondaURL::StripScheme::no,
0, // don't strip any path characters
specs::CondaURL::Credentials::Remove
);
}
)
.or_else(

View File

@ -1637,3 +1637,22 @@ def test_ca_certificates(tmp_path):
)
assert root_prefix_ca_certificates_used or fall_back_certificates_used
def test_non_url_encoding(tmp_path):
# Non-regression test for https://github.com/mamba-org/mamba/issues/3737
env_prefix = tmp_path / "env-non_url_encoding"
# Use linux-64 without loss of generality
out = helpers.create("--json", "x264>=1!0", "-p", env_prefix, "--platform", "linux-64")
# Check that the URL of the build of x264 is encoded.
encoded_url_start = "https://conda.anaconda.org/conda-forge/linux-64/x264-1%21"
x264_package = next(pkg for pkg in out["actions"]["LINK"] if pkg["name"] == "x264")
assert x264_package["url"].startswith(encoded_url_start)
# Export an explicit specification of the environment and check that the URL is not encoded
non_encoded_url_start = "https://conda.anaconda.org/conda-forge/linux-64/x264-1!"
out = helpers.run_env("export", "-p", env_prefix, "--explicit")
assert non_encoded_url_start in out