diff --git a/news/13523.bugfix.rst b/news/13523.bugfix.rst new file mode 100644 index 00000000000..126225fddb0 --- /dev/null +++ b/news/13523.bugfix.rst @@ -0,0 +1 @@ +Fix command parsing for ``pip install []`` with whitespace between file path and extras section. diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 056e7e3a7f1..76c8c38499a 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -47,7 +47,7 @@ def _strip_extras(path: str) -> tuple[str, str | None]: m = re.match(r"^(.+)(\[[^\]]+\])$", path) extras = None if m: - path_no_extras = m.group(1) + path_no_extras = m.group(1).rstrip() extras = m.group(2) else: path_no_extras = path diff --git a/tests/unit/test_req.py b/tests/unit/test_req.py index a2c4cf243ca..0a245fab6a3 100644 --- a/tests/unit/test_req.py +++ b/tests/unit/test_req.py @@ -768,6 +768,7 @@ def test_requirement_file(self) -> None: ("pkg [ext] == 1.0; python_version<='3.6'", "pkg==1.0"), ("pkg-all.allowed_chars0 ~= 2.0", "pkg-all.allowed_chars0~=2.0"), ("pkg-all.allowed_chars0 [ext] ~= 2.0", "pkg-all.allowed_chars0~=2.0"), + ("simple-0.1-py2.py3-none-any.whl [ext]", "simple==0.1"), ], ) def test_install_req_drop_extras(self, inp: str, out: str) -> None: