8000 Change order of absolute path and normalize in the theme folder by rmartinc · Pull Request #34153 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static File getFile(File root, String resource) throws IOException {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ResourceLoaderTest {

Expand Down Expand Up @@ -48,6 +49,10 @@ public void testFiles() throws IOException {
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 {
Expand Down
0