Skip to content

Commit

Permalink
vcs: fix parsing of basic auth http(s) credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Nov 22, 2024
1 parent 23ad2f7 commit 1833a5a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


PROTOCOL = r"\w+"
USER = r"[a-zA-Z0-9_.-]+"
# https://url.spec.whatwg.org/#forbidden-host-code-point
URL_RESTRICTED = r"[^/\?#:@<>\[\]\|]"
USER = rf"{URL_RESTRICTED}+"
USER_AUTH_HTTP = rf"((?P<username>{USER})(:(?P<password>{URL_RESTRICTED}*))?)"
RESOURCE = r"[a-zA-Z0-9_.-]+"
PORT = r"\d+"
PATH = r"[%\w~.\-\+/\\\$]+"
Expand All @@ -32,14 +35,24 @@
PATTERNS = [
re.compile(
r"^(git\+)?"
r"(?P<protocol>https?|git|ssh|rsync|file)://"
r"(?P<protocol>git|ssh|rsync|file)://"
rf"(?:(?P<user>{USER})@)?"
rf"(?P<resource>{RESOURCE})?"
rf"(:(?P<port>{PORT}))?"
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
rf"{PATTERN_SUFFIX}"
),
re.compile(
r"^(git\+)?"
r"(?P<protocol>https?)://"
rf"(?:(?P<user>{USER_AUTH_HTTP})@)?"
rf"(?P<resource>{RESOURCE})?"
rf"(:(?P<port>{PORT}))?"
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
rf"{PATTERN_SUFFIX}"
),
re.compile(
r"(git\+)?"
rf"((?P<protocol>{PROTOCOL})://)"
Expand Down
36 changes: 36 additions & 0 deletions tests/vcs/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,42 @@ def test_normalize_url(url: str, normalized: GitUrl) -> None:
None,
),
),
(
"git+https://username:@github.com/sdispater/pendulum",
ParsedUrl(
"https",
"github.com",
"/sdispater/pendulum",
"username:",
None,
"pendulum",
None,
),
),
(
"git+https://username:[email protected]/sdispater/pendulum",
ParsedUrl(
"https",
"github.com",
"/sdispater/pendulum",
"username:password",
None,
"pendulum",
None,
),
),
(
"git+https://username+suffix:[email protected]/sdispater/pendulum",
ParsedUrl(
"https",
"github.com",
"/sdispater/pendulum",
"username+suffix:password",
None,
"pendulum",
None,
),
),
(
"git+https://github.com/sdispater/pendulum#7a018f2d075b03a73409e8356f9b29c9ad4ea2c5",
ParsedUrl(
Expand Down

0 comments on commit 1833a5a

Please sign in to comment.