Skip to content

Commit cd54253

Browse files
authored
Merge pull request #230 from Gallaecio/credential-case
canonicalize_url: do not apply lowercase to userinfo
2 parents d7c3307 + a4b444c commit cd54253

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

tests/test_url.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,12 @@ def test_domains_are_case_insensitive(self):
13841384
canonicalize_url("http://www.EXAMPLE.com/"), "http://www.example.com/"
13851385
)
13861386

1387+
def test_userinfo_is_case_sensitive(self):
1388+
self.assertEqual(
1389+
canonicalize_url("sftp://UsEr:PaSsWoRd@www.EXAMPLE.com/"),
1390+
"sftp://UsEr:PaSsWoRd@www.example.com/",
1391+
)
1392+
13871393
def test_canonicalize_idns(self):
13881394
self.assertEqual(
13891395
canonicalize_url("http://www.bücher.de?q=bücher"),

w3lib/url.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,13 @@ def canonicalize_url(
654654

655655
fragment = "" if not keep_fragments else fragment
656656

657+
# Apply lowercase to the domain, but not to the userinfo.
658+
netloc_parts = netloc.split("@")
659+
netloc_parts[-1] = netloc_parts[-1].lower().rstrip(":")
660+
netloc = "@".join(netloc_parts)
661+
657662
# every part should be safe already
658-
return urlunparse(
659-
(scheme, netloc.lower().rstrip(":"), path, params, query, fragment)
660-
)
663+
return urlunparse((scheme, netloc, path, params, query, fragment))
661664

662665

663666
def _unquotepath(path: str) -> bytes:

0 commit comments

Comments
 (0)