Skip to content

Commit

Permalink
Disallow ability to create a conda env with : in the prefix (#13044)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Holth <dholth@anaconda.com>
Co-authored-by: Ken Odegard <kodegard@anaconda.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Aug 31, 2023
1 parent 417b797 commit 74f5e63
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conda/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@


def check_prefix(prefix, json=False):
if os.pathsep in prefix:
raise CondaValueError(
f"Cannot create a conda environment with '{os.pathsep}' in the prefix. Aborting."
)
name = basename(prefix)
error = None
if name == ROOT_ENV_NAME:
Expand Down
19 changes: 19 additions & 0 deletions news/12749-no-colon-in-prefix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Disallow ability to create a conda environment with a colon in the prefix. (#13044)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
20 changes: 19 additions & 1 deletion tests/conda_env/test_create.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from os import environ
from pathlib import Path
from uuid import uuid4

import pytest
from pytest import MonkeyPatch

from conda.base.context import context, reset_context
from conda.common.compat import on_win
from conda.core.prefix_data import PrefixData
from conda.exceptions import CondaValueError
from conda.testing import CondaCLIFixture
from conda.testing.integration import package_is_installed
from conda.testing.integration import Commands, package_is_installed, run_command

from . import support_file
from .utils import make_temp_envs_dir
Expand Down Expand Up @@ -250,3 +253,18 @@ def test_create_update_remote_env_file(
# This ends up sticking around since there is no real way of knowing that an environment
# variable _used_ to be in the variables dict, but isn't any more.
assert env_vars["GETS_DELETED"] == "not_actually_removed_though"


@pytest.mark.skipif(on_win, reason="Test is invalid on Windows")
def test_fail_to_create_env_in_dir_with_colon(
tmp_path: Path, conda_cli: CondaCLIFixture
):
# Add a directory with a colon
colon_dir = tmp_path / "fake:dir"
colon_dir.mkdir()

with pytest.raises(
CondaValueError,
match="Cannot create a conda environment with ':' in the prefix.",
):
conda_cli("create", f"--prefix={colon_dir}/tester")

0 comments on commit 74f5e63

Please sign in to comment.