diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-14 08:59:31 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-05 01:53:28 +0100 |
commit | c3255c4473dd3976361ac52899c504c7f70c4be9 (patch) | |
tree | 6e0071afd7dda52d4ec9f291ad23220aca4bb5e2 /src | |
parent | b74f8b6b0d0f080cff5f5ff78d88dc4d7d2165a1 (diff) |
Fix Uri::resolve for base URIs without authority
Previously
Uri::parse("foo").unwrap().resolve(&Uri::parse("bar").unwrap()).to_string()
resulted in "foo/bar".
According to RFC 3986 it should however result in "bar".
See https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.3.
Fixes #4.
Diffstat (limited to 'src')
-rw-r--r-- | src/uri.rs | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -556,7 +556,7 @@ impl Uri { // RFC describes this as: // "T.path = merge(Base.path, R.path);" let mut path = self.path.clone(); - if path.len() > 1 { + if self.authority.is_none() || path.len() > 1 { path.pop(); } path.extend( @@ -1458,6 +1458,7 @@ mod tests { ("http://a/b/c/d;p?q", "../../", "http://a").into(), ("http://a/b/c/d;p?q", "../../g", "http://a/g").into(), // Here are some examples of our own. + ("foo", "bar", "bar").into(), ("http://example.com", "foo", "http://example.com/foo").into(), ("http://example.com/", "foo", "http://example.com/foo").into(), ("http://example.com", "foo/", "http://example.com/foo/").into(), |