Change order of absolute path and normalize in the theme folder (#34153)
Closes #34028 Signed-off-by: rmartinc <rmartinc@redhat.com>
This commit is contained in:
parent
271e749c82
commit
a84a2c2ac2
2 changed files with 6 additions and 1 deletions
|
@ -36,7 +36,7 @@ public class ResourceLoader {
|
|||
if (root == null || resource == null) {
|
||||
return null;
|
||||
}
|
||||
Path rootPath = root.toPath().normalize().toAbsolutePath();
|
||||
Path rootPath = root.toPath().toAbsolutePath().normalize();
|
||||
Path resourcePath = rootPath.resolve(resource).normalize().toAbsolutePath();
|
||||
if (resourcePath.startsWith(rootPath)) {
|
||||
return resourcePath.toFile();
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class ResourceLoaderTest {
|
||||
|
||||
|
@ -48,6 +49,10 @@ public class ResourceLoaderTest {
|
|||
assertFileAsStream(parent, DOUBLE + "myresource.css", false, false);
|
||||
|
||||
assertFileAsStream(new File(tempDirectory.toFile(), "test/../resources/"), "myresource.css", true, true);
|
||||
|
||||
// relativize tmp folder to the current working directory, something like ../../../tmp/path
|
||||
Path relativeParent = Paths.get(".").toAbsolutePath().relativize(parent.toPath());
|
||||
assertFileAsStream(relativeParent.toFile(), "myresource.css", true, true);
|
||||
}
|
||||
|
||||
private void assertResourceAsStream(String parent, String resource, boolean expectValid, boolean expectResourceToExist) throws IOException {
|
||||
|
|
Loading…
Reference in a new issue