Resolving sub-paths is not working correctly
Opened this issue · 2 comments
In the TestPath
there is already a test case to illustrate this. Currently, it looks like this:
/**
* Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
*/
@Test
public void testRelativizeResolveCombination() {
Path p = Paths.get(clusterUri).resolve("/a/b");
Path q = p.getFileSystem().getPath("c", "d");
assertEquals(q, p.relativize(p.resolve(q)));
}
If you change it to:
/**
* Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
*/
@Test
public void testRelativizeResolveCombination() {
Path p = Paths.get(clusterUri).resolve("/a/b");
Path q = p.getFileSystem().getPath("c", "d");
Path qa = q.toAbsolutePath();
assertEquals("/a/b/c/d", qa.toString());
assertEquals(q, p.relativize(p.resolve(q)));
}
You will see that the first assertion will fail, because the actual returned value for it is /c/d
. The above will also fail, if you have Path q = p.resolve("c/d");
. This is incorrect. Could you please fix it? :)
hello @carlspring and sorry for the long reply and thanks for the full description.
I will take a look at it soon.
made some tests and I don't see bug here.
Even the unit test is good.
Let me share more tests I made:
/**
* Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
*/
@Test
public void testRelativizeResolveCombination() {
Path p = Paths.get(clusterUri).resolve("/a/b");
Path q = p.getFileSystem().getPath("c", "d");
assertEquals("/a/b", p.toString());
assertEquals("c/d", q.toString());
assertEquals("/a/b/c/d", p.resolve(q).toString());
assertEquals(q, p.relativize(p.resolve(q)));
Path qa = q.toAbsolutePath();
assertEquals("c/d", q.toString());
assertEquals("/c/d", qa.toString());
}
If you convert q
(which is c/d
) to absolute path with q.toAbsolutePath()
you can't have the complete /a/b/c/d
path.
Because if you don't do "resolve" or "relativize" between the two paths you can't combine it.