Skip to content

Commit cc87b3e

Browse files
abnradoering
authored andcommitted
vcs: fix parsing of basic auth http(s) credentials
1 parent 065808a commit cc87b3e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/poetry/core/vcs/git.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212

1313
PROTOCOL = r"\w+"
14-
USER = r"[a-zA-Z0-9_.-]+"
14+
# https://url.spec.whatwg.org/#forbidden-host-code-point
15+
URL_RESTRICTED = r"[^/\?#:@<>\[\]\|]"
16+
USER = rf"{URL_RESTRICTED}+"
17+
USER_AUTH_HTTP = rf"((?P<username>{USER})(:(?P<password>{URL_RESTRICTED}*))?)"
1518
RESOURCE = r"[a-zA-Z0-9_.-]+"
1619
PORT = r"\d+"
1720
PATH = r"[%\w~.\-\+/\\\$]+"
@@ -32,14 +35,24 @@
3235
PATTERNS = [
3336
re.compile(
3437
r"^(git\+)?"
35-
r"(?P<protocol>https?|git|ssh|rsync|file)://"
38+
r"(?P<protocol>git|ssh|rsync|file)://"
3639
rf"(?:(?P<user>{USER})@)?"
3740
rf"(?P<resource>{RESOURCE})?"
3841
rf"(:(?P<port>{PORT}))?"
3942
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
4043
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
4144
rf"{PATTERN_SUFFIX}"
4245
),
46+
re.compile(
47+
r"^(git\+)?"
48+
r"(?P<protocol>https?)://"
49+
rf"(?:(?P<user>{USER_AUTH_HTTP})@)?"
50+
rf"(?P<resource>{RESOURCE})?"
51+
rf"(:(?P<port>{PORT}))?"
52+
rf"(?P<pathname>[:/\\]({PATH}[/\\])?"
53+
rf"((?P<name>{NAME}?)(\.git|[/\\])?)?)"
54+
rf"{PATTERN_SUFFIX}"
55+
),
4356
re.compile(
4457
r"(git\+)?"
4558
rf"((?P<protocol>{PROTOCOL})://)"

tests/vcs/test_vcs.py

+36
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)