From d3f1e1bec01a370bda2f5de969d919d2d0606566 Mon Sep 17 00:00:00 2001 From: DanGould Date: Fri, 27 Dec 2024 15:22:32 -0500 Subject: [PATCH] Fix fragment parameter case sensitivity Bech32 fragment parameters should not be case sensitive. This fixes that by converting params and bech32 HRPs they match against to uppercase. Close #442 --- payjoin/src/uri/url_ext.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/payjoin/src/uri/url_ext.rs b/payjoin/src/uri/url_ext.rs index b5047ee5..f347e52b 100644 --- a/payjoin/src/uri/url_ext.rs +++ b/payjoin/src/uri/url_ext.rs @@ -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(¶m.to_uppercase()); } } } @@ -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); + } }