From d63f2ffb8bd02b8d08d7484148633b3c4dc6bb1a Mon Sep 17 00:00:00 2001 From: DanGould Date: Tue, 22 Oct 2024 15:01:47 -0400 Subject: [PATCH] Decode pj parameter `#` in `deserialize_temp` --- payjoin/src/uri/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/payjoin/src/uri/mod.rs b/payjoin/src/uri/mod.rs index 16909519..7a719a26 100644 --- a/payjoin/src/uri/mod.rs +++ b/payjoin/src/uri/mod.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use bitcoin::address::NetworkChecked; use bitcoin::{Address, Amount}; pub use error::PjParseError; -use percent_encoding_rfc3986::{utf8_percent_encode, AsciiSet, CONTROLS}; +use percent_encoding_rfc3986::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS}; use url::Url; use crate::uri::error::InternalPjParseError; @@ -224,8 +224,12 @@ impl<'a> bip21::de::DeserializationState<'a> for DeserializationState { > { match key { "pj" if self.pj.is_none() => { - let endpoint = Cow::try_from(value).map_err(|_| InternalPjParseError::NotUtf8)?; - let url = Url::parse(&endpoint).map_err(|_| InternalPjParseError::BadEndpoint)?; + let encoded = Cow::try_from(value).map_err(|_| InternalPjParseError::NotUtf8)?; + let decoded = percent_decode_str(&encoded) + .map_err(|_| InternalPjParseError::BadEndpoint)? + .decode_utf8() + .map_err(|_| InternalPjParseError::NotUtf8)?; + let url = Url::parse(&decoded).map_err(|_| InternalPjParseError::BadEndpoint)?; self.pj = Some(url); Ok(bip21::de::ParamKind::Known)