Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathPath implementation does not conform to the spec. #1

Closed
noeppi-noeppi opened this issue Jun 13, 2022 · 1 comment
Closed

PathPath implementation does not conform to the spec. #1

noeppi-noeppi opened this issue Jun 13, 2022 · 1 comment

Comments

@noeppi-noeppi
Copy link

A lot of methods are wrong. Here is some sample test code that compares the PathFS with a standard JarFS:

FileSystem jarFs = FileSystems.newFileSystem(URI.create("jar:file:/path/to/JarJar/src/binks/resources/dir1.zip"), new HashMap<>());
FileSystem pathFs = FileSystems.newFileSystem(URI.create("path:///test"), ImmutableMap.of("packagePath", Paths.get("/path/to/JarJar/src/binks/resources/dir1.zip")));

System.out.println("normalize + absolute: jarfs:  " + jarFs.getPath("/abc/../../def").normalize().isAbsolute());
System.out.println("normalize + absolute: pathfs: " + pathFs.getPath("/abc/../../def").normalize().isAbsolute());
System.out.println("relativize:           jarfs:  " + jarFs.getPath("/abc/xyz").relativize(jarFs.getPath("/abc/def/ghi")));
System.out.println("relativize:           pathfs: " + pathFs.getPath("/abc/xyz").relativize(pathFs.getPath("/abc/def/ghi")));
System.out.println("name count:           jarfs:  " + jarFs.getPath("/abc/xyz").getNameCount());
System.out.println("name count:           pathfs: " + pathFs.getPath("/abc/xyz").getNameCount());
System.out.println("root:                 jarfs:  " + jarFs.getPath("abc/xyz").getRoot());
System.out.println("root:                 pathfs: " + pathFs.getPath("abc/xyz").getRoot());
System.out.println("parent:               jarfs:  " + jarFs.getPath("").getParent());
System.out.println("parent:               pathfs: " + pathFs.getPath("").getParent());

This gives

normalize + absolute: jarfs:  true
normalize + absolute: pathfs: false
relativize:           jarfs:  ../def/ghi
relativize:           pathfs: ../abc/def/ghi
name count:           jarfs:  2
name count:           pathfs: 3
root:                 jarfs:  null
root:                 pathfs: /
parent:               jarfs:  null
parent:               pathfs: 

As you can see, some outputs are completely wrong. Like an absolute path should not get relative when normalizing.

Currently JarJar faces similar problems as securejarhandler did. My proposed solution to the problem is to copy the path implementation from McModLauncher/securejarhandler#26 into JarJar as it has extensive tests against a JarFS and (to my knowledge) fulfills the Path spec.

@marchermans
Copy link
Contributor

@noeppi-noeppi Can you send me the spec for Path objects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants