From 85095442697834576f727993bcd9123b44dd9f29 Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Thu, 24 Oct 2024 10:41:19 +0200 Subject: [PATCH] Relativize: remove a too harsh condition leading to the use of absolute paths --- src/lib.rs | 2 +- tests/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3c450b1..38a4c1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -712,7 +712,7 @@ impl> Iri { let number_of_shared_characters = abs_path[..number_of_shared_characters] .rfind('/') .map_or(0, |n| n + 1); - return if abs_path[number_of_shared_characters..].contains('/') + return if abs_path[number_of_shared_characters..].starts_with('/') || base_path[number_of_shared_characters..].contains('/') || abs_path[number_of_shared_characters..].contains(':') { diff --git a/tests/lib.rs b/tests/lib.rs index 84fe908..c914196 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1015,7 +1015,7 @@ fn test_relativize_iri() { ( "http://example.com/foo/bar", "http://example.com/foo", - "/foo/bar", + "foo/bar", ), ( "http://example.com/foo?bar", @@ -1067,7 +1067,7 @@ fn test_relativize_iri() { ("urn:ab", "urn:", "ab"), ("urn:isbn:foo", "urn:", "urn:isbn:foo"), ("urn:is/bn:foo", "urn:", "is/bn:foo"), - ("t:e/e/p", "t:e/s", "t:e/e/p"), + ("t:e/e/p", "t:e/s", "e/p"), ("htt:/foo/gp", "htt:/foo/", "gp"), ("htt:/gp", "htt:/", "gp"), ("x:", "x://foo", "x:"), @@ -1077,6 +1077,7 @@ fn test_relativize_iri() { ("http://example.com", "http://example.com#foo", ""), ("http://example.com/a/", "http://example.com/a/b", "."), ("http://example.com/a/?c", "http://example.com/a/b", ".?c"), + ("t:o//", "t:o/", "t:o//"), ]; for (original, base, output) in examples {