8000 Make the revision part percent-encoded in version control URLs by kazssym · Pull Request #13407 · pypa/pip · GitHub
[go: up one dir, main page]

Skip to content

Make the revision part percent-encoded in version control URLs #13407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions news/13407.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Modified to percent-encode the revision part in version control URLs.
For example, use ``git+https://example.com/repo.git@issue%231`` to specify the branch ``issue#1``.
If you previously used a branch name containing a ``%`` character in a version control URL, you now need to replace it with ``%25`` to ensure correct percent-encoding.
4 changes: 3 additions & 1 deletion src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def make_vcs_requirement_url(
repo_url: the remote VCS url, with any needed VCS prefix (e.g. "git+").
project_name: the (unescaped) project name.
"""
quoted_rev = urllib.parse.quote(rev)
egg_project_name = project_name.replace("-", "_")
req = f"{repo_url}@{rev}#egg={egg_project_name}"
req = f"{repo_url}@{quoted_rev}#egg={egg_project_name}"
if subdir:
req += f"&subdirectory={subdir}"

Expand Down Expand Up @@ -397,6 +398,7 @@ def get_url_rev_and_auth(cls, url: str) -> tuple[str, str | None, AuthInfo]:
"which is not supported. Include a revision after @ "
"or remove @ from the URL."
)
rev = urllib.parse.unquote(rev)
url = urllib.parse.urlunsplit((scheme, netloc, path, query, ""))
return url, rev, user_pass

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def test_ensure_svn_available() -> None:
("git+https://example.com/pkg", "dev", "zope-interface"),
"git+https://example.com/pkg@dev#egg=zope_interface",
),
# Test a revision with special characters.
(
("git+https://example.com/pkg", "dev@1#2", "myproj"),
"git+https://example.com/pkg@dev%401%232#egg=myproj",
),
],
)
def test_make_vcs_requirement_url(args: tuple[Any, ...], expected: str) -> None:
Expand Down Expand Up @@ -394,6 +399,11 @@ def test_git__get_url_rev__idempotent() -> None:
"svn+https://svn.example.com/My+Project",
("https://svn.example.com/My+Project", None, (None, None)),
),
# Test percent-encoded characters in revision.
(
"svn+https://svn.example.com/MyProject@dev%401%232",
("https://svn.example.com/MyProject", "dev@1#2", (None, None)),
),
],
)
def test_version_control__get_url_rev_and_auth(
Expand Down
Loading
0