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 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 payjoin#442
  • Loading branch information
DanGould committed Dec 28, 2024
1 parent f7cb8b7 commit dfaf948
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions payjoin/src/uri/url_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,19 @@ impl UrlExt for Url {
}
}

/// Get a parameter from the URL fragment
///
/// This function is case insensitive
fn get_param<F, T>(url: &Url, prefix: &str, parse: F) -> Option<T>
where
F: Fn(&str) -> Option<T>,
{
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) {
Expand Down

0 comments on commit dfaf948

Please sign in to comment.