Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.7.3
-
None
-
Unknown
Description
None of these tests pass:
@Test public void testRelativize() throws Exception { URI ab = URI.create("http://example.com/a/b/"); URI abcd = URI.create("http://example.com/a/b/c/d"); assertEquals(URI.create(""), HttpUtils.relativize(ab, ab)); assertEquals(URI.create("c/d"), HttpUtils.relativize(ab, abcd)); assertEquals(URI.create("../"), HttpUtils.relativize(abcd, ab)); assertEquals(URI.create(""), HttpUtils.relativize(abcd, abcd)); URI abcd2 = URI.create("http://example.com/a/b/c/d2"); assertEquals(URI.create("d2"), HttpUtils.relativize(abcd, abcd2)); URI ab2cd = URI.create("http://example.com/a/b2/c/d"); assertEquals(URI.create("../../b2/c/d"), HttpUtils.relativize(abcd, ab2cd)); }
This affects LinkBuilder.buildRelativize() and UriInfo.relativize()
The algorithm is basically working by counting elements common by position - this would also fail hard when there are common elements later - but with a different ancestor.
Javadoc for UriInfo.relativize() also has some testcases that should work.