Skip to content

Commit

Permalink
Fix fragment parameter case sensitivity
Browse files Browse the repository at this point in the history
Bech32 fragment parameters should not be case sensitive. This fixes that
by converting params and bech32 HRPs they match against to uppercase.

Close #442
  • Loading branch information
DanGould committed Dec 28, 2024
1 parent f7cb8b7 commit d3f1e1b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions payjoin/src/uri/url_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ where
{
if let Some(fragment) = url.fragment() {
for param in fragment.split('+') {
if param.starts_with(prefix) {
return parse(param);
if param.to_uppercase().starts_with(&prefix.to_uppercase()) {
return parse(&param.to_uppercase());
}
}
}
Expand Down Expand Up @@ -297,4 +297,21 @@ mod tests {
assert!(pjuri.extras.endpoint().ohttp().is_ok());
assert_eq!(format!("{}", pjuri), uri);
}

#[test]
fn test_case_insensitive_params() {
let mut url = Url::parse("https://example.com").unwrap();

let serialized = "OH1QYPM5JXYNS754Y4R45QWE336QFX6ZR8DQGVQCULVZTV20TFVEYDMFQC";
let ohttp_keys = OhttpKeys::from_str(serialized).unwrap();
url.set_ohttp(ohttp_keys.clone());

let lowercase_url =
Url::parse(&format!("https://example.com#{}", serialized.to_lowercase())).unwrap();
assert_eq!(lowercase_url.ohttp().unwrap(), ohttp_keys);

let mixed_case_url =
Url::parse(&format!("https://example.com#oh1{}", &serialized[3..])).unwrap();
assert_eq!(mixed_case_url.ohttp().unwrap(), ohttp_keys);
}
}

0 comments on commit d3f1e1b

Please sign in to comment.