Skip to content

Commit ad320a7

Browse files
committed
also percent-encode %
1 parent 26aa072 commit ad320a7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/url.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@ fn is_punnycode_domain(lib_url: &Url, domain: &str) -> bool {
603603
}
604604

605605
/// See <https://url.spec.whatwg.org/#userinfo-percent-encode-set>
606-
///
607-
/// Note that this doesn't actually include % itself - see the note in
608-
/// https://url.spec.whatwg.org/#string-percent-encode-after-encoding
609606
const USERINFO_ENCODE_SET: &AsciiSet = &CONTROLS
610607
// query percent-encodes is controls plus the below
611608
.add(b' ')
@@ -628,7 +625,10 @@ const USERINFO_ENCODE_SET: &AsciiSet = &CONTROLS
628625
.add(b'[')
629626
.add(b'\\')
630627
.add(b']')
631-
.add(b'|');
628+
.add(b'|')
629+
// https://datatracker.ietf.org/doc/html/rfc3986.html#section-2.4
630+
// we must also percent-encode '%'
631+
.add(b'%');
632632

633633
fn encode_userinfo_component(value: &str) -> Cow<'_, str> {
634634
let encoded = percent_encode(value.as_bytes(), USERINFO_ENCODE_SET).to_string();

tests/validators/test_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,11 @@ def test_multi_url_build_hosts_encodes_credentials() -> None:
13451345
]
13461346
url = MultiHostUrl.build(scheme='postgresql', hosts=hosts)
13471347
assert (
1348-
str(url) == 'postgresql://user%20name:p%40ss%2Fword%3F%23__@example.com:5431,other:p%40%ss__@example.org:5432'
1348+
str(url) == 'postgresql://user%20name:p%40ss%2Fword%3F%23__@example.com:5431,other:p%40%25ss__@example.org:5432'
13491349
)
13501350
assert url.hosts() == [
13511351
{'username': 'user%20name', 'password': 'p%40ss%2Fword%3F%23__', 'host': 'example.com', 'port': 5431},
1352-
{'username': 'other', 'password': 'p%40%ss__', 'host': 'example.org', 'port': 5432},
1352+
{'username': 'other', 'password': 'p%40%25ss__', 'host': 'example.org', 'port': 5432},
13531353
]
13541354

13551355

0 commit comments

Comments
 (0)