Skip to content

Commit

Permalink
Decode pj parameter # in deserialize_temp
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Oct 22, 2024
1 parent 874733e commit d63f2ff
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions payjoin/src/uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d63f2ff

Please sign in to comment.