From dfaf9486dd715a580c80f1200a569fad10dd41f5 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 Hrp|'1' prefixes they match against to uppercase. Note that this implementation implies all fragment parameters must be case insentitive, which needs to be specified in BIP 77. Close #442 --- payjoin/src/uri/url_ext.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/payjoin/src/uri/url_ext.rs b/payjoin/src/uri/url_ext.rs index b5047ee5c..94a7c6e85 100644 --- a/payjoin/src/uri/url_ext.rs +++ b/payjoin/src/uri/url_ext.rs @@ -97,18 +97,19 @@ impl UrlExt for Url { } } +/// Get a parameter from the URL fragment +/// +/// This function is case insensitive fn get_param(url: &Url, prefix: &str, parse: F) -> Option where F: Fn(&str) -> Option, { - if let Some(fragment) = url.fragment() { - for param in fragment.split('+') { - if param.starts_with(prefix) { - return parse(param); - } - } - } - None + let prefix = prefix.to_uppercase(); + url.fragment()? + .to_uppercase() + .split('+') + .find(|param| param[..prefix.len()] == prefix) + .and_then(parse) } fn set_param(url: &mut Url, prefix: &str, param: &str) {