PR #11433 - fix for symlink loops in Resource.getAllResources

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2024-02-23 15:44:01 +11:00
parent 9234331d62
commit 5826e56666
2 changed files with 10 additions and 7 deletions

View File

@ -405,7 +405,16 @@ public abstract class Resource implements Iterable<Resource>
boolean noDepth = true;
for (Iterator<Resource> i = children.iterator(); noDepth && i.hasNext(); )
noDepth = !i.next().isDirectory();
{
Resource resource = i.next();
if (resource.isDirectory())
{
// If the directory is a symlink we do not want to go any deeper.
Path resourcePath = resource.getPath();
if (resourcePath == null || !Files.isSymbolicLink(resourcePath))
noDepth = false;
}
}
if (noDepth)
return children;

View File

@ -27,7 +27,6 @@ import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jetty.toolchain.test.FS;
@ -728,11 +727,6 @@ public class PathResourceTest
resource.resolve("foo.txt")
};
List<String> actual = allResources.stream()
.map(Resource::getURI)
.map(URI::toASCIIString)
.toList();
assertThat(allResources, containsInAnyOrder(expected));
}
}