Fix recent regression in PathMatchingResourcePatternResolver
Commit 0eb66789ed which introduced generic FileSystem support in
PathMatchingResourcePatternResolver also introduced a regression in that
a matching folder is now returned in the results.
This commit address this by additionally using Files#isRegularFile() in
the predicate used to filter candidates.
Closes gh-29163
This commit is contained in:
@@ -764,14 +764,15 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
try {
|
||||
Path rootPath = fileSystem.getPath(rootDir);
|
||||
String resourcePattern = rootPath.resolve(subPattern).toString();
|
||||
Predicate<Path> resourcePatternMatches = path -> getPathMatcher().match(resourcePattern, path.toString());
|
||||
Predicate<Path> isMatchingFile =
|
||||
path -> Files.isRegularFile(path) && getPathMatcher().match(resourcePattern, path.toString());
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Searching directory [%s] for files matching pattern [%s]"
|
||||
.formatted(rootPath.toAbsolutePath(), subPattern));
|
||||
}
|
||||
Set<Resource> result = new LinkedHashSet<>();
|
||||
try (Stream<Path> files = Files.walk(rootPath)) {
|
||||
files.filter(resourcePatternMatches).sorted().forEach(file -> {
|
||||
files.filter(isMatchingFile).sorted().forEach(file -> {
|
||||
try {
|
||||
result.add(convertToResource(file.toUri()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user