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 payjoin#442
  • Loading branch information
DanGould committed Dec 27, 2024
1 parent f202098 commit c071745
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 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,23 @@ 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());

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

// Test mixed case parameter
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 c071745

Please sign in to comment.