Skip to content

Commit

Permalink
Ignore RFC 3986 fragments in BIP 21 URIs
Browse files Browse the repository at this point in the history
Although behavior for when encountering RFC 3986 fragments in BIP 21
URIs is not specified, according to RFC 3986 it is unambiguously not
query data and therefore should be excluded from BIP 21 query
parameters.

[WIP] squash with parent commits:
c88442f failing test that fragments aren't parsed for params
51f8b88 failing test that fragment separator is ignored
  • Loading branch information
nothingmuch committed Oct 24, 2024
1 parent 2203d3c commit f50ebb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ impl<'a, T: DeserializeParams<'a>> Uri<'a, bitcoin::address::NetworkUnchecked, T
let mut label = None;
let mut message = None;
if let Some(params) = params {
// [RFC 3986 § 3.4](https://www.rfc-editor.org/rfc/rfc3986#section-3.4):
//
// > The query component is indicated by the first question
// > mark ("?") character and terminated by a number sign ("#") character
// > or by the end of the URI.
let params = match params.find('#') {
Some(pos) => &params[..pos],
None => params,
};

for param in params.split('&') {
let pos = param
.find('=')
Expand Down
6 changes: 3 additions & 3 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ impl<'a, W: fmt::Write> fmt::Write for EqSignChecker<'a, W> {
/// > otherparam = qchar *qchar [ "=" *qchar ]
/// > ```
/// ...
/// > Here, "qchar" corresponds to valid characters of an RFC 3986 URI > query
/// component, excluding the "=" and "&" characters, which this BIP > takes as
/// separators.
/// > Here, "qchar" corresponds to valid characters of an RFC 3986 URI query
/// > component, excluding the "=" and "&" characters, which this BIP takes as
/// > separators.
///
/// [RFC 3986 Appendix A](https://www.rfc-editor.org/rfc/rfc3986#appendix-A):
///
Expand Down

0 comments on commit f50ebb5

Please sign in to comment.