Skip to content

Commit

Permalink
Work around '#' escaping bug in bip21 crate
Browse files Browse the repository at this point in the history
bip21 dependency temporarily specified to use bugfix PR branch

The `pj` parameter of the BIP 21 URL is itself a URL which contains a
fragment.

This is not escaped by bip21 during serialization, which according to
RFC 3986 truncates the `pj` parameter, making everything that follows
part of the fragment.

Deserialization likewise ignores #, parsing it as part of the value
which round trips with the incorrect serialization behavior.

Temporarily depend on bugfix pr branch for bip21
  • Loading branch information
nothingmuch committed Oct 23, 2024
1 parent a9b9a34 commit f2b9dfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion payjoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ danger-local-https = ["io", "reqwest/rustls-tls", "rustls"]

[dependencies]
bitcoin = { version = "0.32.2", features = ["base64"] }
bip21 = "0.5.0"
bip21 = { git = "https://github.com/Kixunil/bip21.git", rev = "refs/pull/26/head" }
hpke = { package = "bitcoin-hpke", version = "0.13.0", optional = true }
log = { version = "0.4.14"}
http = { version = "1", optional = true }
Expand Down
19 changes: 15 additions & 4 deletions payjoin/src/uri/url_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,20 @@ mod tests {
#[test]
fn test_valid_v2_url_fragment_on_bip21() {
let uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\
&pj=https://example.com\
#ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw";
let uri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap();
assert!(uri.extras.endpoint().ohttp().is_some());
&pj=https://example.com/\
%23ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw\
&pjos=0";
let pjuri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap();

assert!(pjuri.extras.endpoint().ohttp().is_some());
assert_eq!(format!("{}", pjuri), uri);

let reordered = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\
&pjos=0&pj=https://example.com/\
%23ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw";
let pjuri =
Uri::try_from(reordered).unwrap().assume_checked().check_pj_supported().unwrap();
assert!(pjuri.extras.endpoint().ohttp().is_some());
assert_eq!(format!("{}", pjuri), uri);
}
}

0 comments on commit f2b9dfa

Please sign in to comment.