Skip to content

Commit acd7161

Browse files
committed
canonicalize_url: do not apply lowercase to userinfo
1 parent d7c3307 commit acd7161

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/test_url.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,11 @@ 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/"), "sftp://UsEr:PaSsWoRd@www.example.com/"
1390+
)
1391+
13871392
def test_canonicalize_idns(self):
13881393
self.assertEqual(
13891394
canonicalize_url("http://www.bücher.de?q=bücher"),

w3lib/url.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,14 @@ 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
658663
return urlunparse(
659-
(scheme, netloc.lower().rstrip(":"), path, params, query, fragment)
664+
(scheme, netloc, path, params, query, fragment)
660665
)
661666

662667

0 commit comments

Comments
 (0)