Repository navigation
Backlog
Backlog
Copy link
Description
Summary
payjoin::Url::join (payjoin/src/core/url.rs:309-353) documents RFC 3986 reference resolution, but both the leading-/ branch (lines 320-324) and the relative branch (lines 325-349) place the entire segment directly into new_url.path and clear new_url.query = None and new_url.fragment = None without splitting query/fragment components via parse_path_query_fragment.
As a result:
base.join("/c?v=2#frag")setspath() == "/c?v=2#frag",query() == None, andfragment() == None.- Calling
query_pairs_mut().append_pair("p", "1")on that result appends?p=1after#frag, producing malformed"https://example.com/c?v=2#frag?p=1"and breaking round-tripUrl::parseinvariants. base.join("c?v=2#frag")setspath() == "/a/c?v=2#frag",query() == None,fragment() == None.base.join("?v=2")againsthttps://example.com/a/bdropsband setspath() == "/a/?v=2",query() == None(RFC 3986 Section 5.2.2 keeps the base path/a/band setsquery = Some("v=2")).
Minimal Reproducer (commit ec98fea8440edef83666e0df250bee321f4f410e)
Add as payjoin/tests/repro_url_join.rs:
use payjoin::Url;
#[test]
fn repro_url_join_query_and_fragment() {
let base = Url::parse("https://example.com/a/b").unwrap();
let mut abs = base.join("/c?v=2#frag").unwrap();
assert_eq!(abs.path(), "/c"); // actual: "/c?v=2#frag"
assert_eq!(abs.query(), Some("v=2")); // actual: None
assert_eq!(abs.fragment(), Some("frag")); // actual: None
abs.query_pairs_mut().append_pair("p", "1");
assert_eq!(abs.as_str(), "https://example.com/c?v=2&p=1#frag"); // actual: ".../c?v=2#frag?p=1"
let rel = base.join("c?v=2#frag").unwrap();
assert_eq!((rel.path(), rel.query(), rel.fragment()), ("/a/c", Some("v=2"), Some("frag")));
let q_only = base.join("?v=2").unwrap();
assert_eq!((q_only.path(), q_only.query()), ("/a/b", Some("v=2")));
}Suggested Fix
Call the existing parse_path_query_fragment(segment) helper (url.rs:540) in Url::join after the scheme check:
- If the parsed path is empty: preserve
new_url.path, replacenew_url.queryonly whenquery.is_some(), and setnew_url.fragment = fragment. - Otherwise, resolve the parsed path (leading
/or relative merge + dot-segment removal) and assignnew_url.query = query; new_url.fragment = fragment;.
Metadata
Metadata
Assignees
Labels
No labels
Activity
CaptainLevi2k04 commentedon Nov 26, 2026
Hi! I'd like to take this issue on.
I went through the reproducer and the suggested fix. My understanding is that the scope is to use the existing
parse_path_query_fragmenthelper inUrl::join, correctly resolve the parsed path, and preserve or update the base query and fragment according to RFC 3986, especially for query-only and fragment-only references.Could one of the maintainers confirm that this is the intended scope before I start implementing it? Please let me know if you'd suggest any changes.
Thanks!