aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-14 08:59:31 +0100
committerMartin Fischer <martin@push-f.com>2021-12-05 01:53:28 +0100
commitc3255c4473dd3976361ac52899c504c7f70c4be9 (patch)
tree6e0071afd7dda52d4ec9f291ad23220aca4bb5e2
parentb74f8b6b0d0f080cff5f5ff78d88dc4d7d2165a1 (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.
-rw-r--r--src/uri.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/uri.rs b/src/uri.rs
index da706f2..25027af 100644
--- a/src/uri.rs
+++ b/src/uri.rs
@@ -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(),