Skip to content

Commit 065cffc

Browse files
committed
vcs: fix parsing of basic auth http(s) credentials
1 parent dcf474d commit 065cffc

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/poetry/core/vcs/git.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212

1313
PROTOCOL = r"\w+"
14-
USER = r"[a-zA-Z0-9_.-]+"
14+
URL_RESTRICTED = r"[^/\?#:@]"
15+
USER = rf"{URL_RESTRICTED}+"
16+
USER_AUTH_HTTP = rf"((?P<username>{USER})(:(?P<password>{URL_RESTRICTED}*))?)"
1517
RESOURCE = r"[a-zA-Z0-9_.-]+"
1618
PORT = r"\d+"
1719
PATH = r"[%\w~.\-\+/\\\$]+"
@@ -32,14 +34,24 @@
3234
PATTERNS = [
3335
re.compile(
3436
r"^(git\+)?"
35-
r"(?P<protocol>https?|git|ssh|rsync|file)://"
37+
r"(?P<protocol>git|ssh|rsync|file)://"
3638
rf"(?:(?P<user>{USER})@)?"
3739
rf"(?P<resource>{RESOURCE})?"
3840
rf"(:(?P<port>{PORT}))?"
3941
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
4042
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
4143
rf"{PATTERN_SUFFIX}"
4244
),
45+
re.compile(
46+
r"^(git\+)?"
47+
r"(?P<protocol>https?)://"
48+
rf"(?:(?P<user>{USER_AUTH_HTTP})@)?"
49+
rf"(?P<resource>{RESOURCE})?"
50+
rf"(:(?P<port>{PORT}))?"
51+
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
52+
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
53+
rf"{PATTERN_SUFFIX}"
54+
),
4355
re.compile(
4456
r"(git\+)?"
4557
rf"((?P<protocol>{PROTOCOL})://)"

tests/vcs/test_vcs.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,42 @@ def test_normalize_url(url: str, normalized: GitUrl) -> None:
272272
None,
273273
),
274274
),
275+
(
276+
"git+https://username:@github.com/sdispater/pendulum",
277+
ParsedUrl(
278+
"https",
279+
"github.com",
280+
"/sdispater/pendulum",
281+
"username:",
282+
None,
283+
"pendulum",
284+
None,
285+
),
286+
),
287+
(
288+
"git+https://username:[email protected]/sdispater/pendulum",
289+
ParsedUrl(
290+
"https",
291+
"github.com",
292+
"/sdispater/pendulum",
293+
"username:password",
294+
None,
295+
"pendulum",
296+
None,
297+
),
298+
),
299+
(
300+
"git+https://username+suffix:[email protected]/sdispater/pendulum",
301+
ParsedUrl(
302+
"https",
303+
"github.com",
304+
"/sdispater/pendulum",
305+
"username+suffix:password",
306+
None,
307+
"pendulum",
308+
None,
309+
),
310+
),
275311
(
276312
"git+https://github.com/sdispater/pendulum#7a018f2d075b03a73409e8356f9b29c9ad4ea2c5",
277313
ParsedUrl(

0 commit comments

Comments
 (0)