Skip to content

Commit 0e9af05

Browse files
authored
Merge pull request #8 from TheBlueMatt/main
Avoid assumption on unicode casing char length and LNURL override for bitcoin: URIs
2 parents d6ef87c + 8460fd3 commit 0e9af05

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ impl PaymentInstructions {
918918
supports_proof_of_payment_callbacks: bool,
919919
) -> Result<PaymentInstructions, ParseError> {
920920
let supports_pops = supports_proof_of_payment_callbacks;
921+
let (uri_proto, _uri_suffix) = split_once(instructions, ':');
922+
921923
if let Ok(hrn) = HumanReadableName::from_encoded(instructions) {
922924
let resolution = hrn_resolver.resolve_hrn(&hrn).await;
923925
let resolution = resolution.map_err(ParseError::HrnResolutionError)?;
@@ -947,7 +949,11 @@ impl PaymentInstructions {
947949
))
948950
},
949951
}
950-
} else if let Some(idx) = instructions.to_lowercase().rfind("lnurl") {
952+
} else if uri_proto.eq_ignore_ascii_case("bitcoin:") {
953+
// If it looks like a BIP 353 URI, jump straight to parsing it and ignore any LNURL
954+
// overrides.
955+
parse_resolved_instructions(instructions, network, supports_pops, None, None)
956+
} else if let Some(idx) = instructions.to_ascii_lowercase().rfind("lnurl") {
951957
let mut lnurl_str = &instructions[idx..];
952958
// first try to decode as a bech32-encoded lnurl, if that fails, try to drop a
953959
// trailing `&` and decode again, this could a http query param

0 commit comments

Comments
 (0)