Skip to content

Commit d17cdf9

Browse files
committed
Restore directory matching (explicitly excluding root path itself)
Closes gh-29333
1 parent d89865a commit d17cdf9

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,9 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
781781
rootDir += "/";
782782
}
783783

784+
Path rootPathForPattern = rootPath;
784785
String resourcePattern = rootDir + StringUtils.cleanPath(subPattern);
785-
Predicate<Path> isMatchingFile = path -> (Files.isRegularFile(path) &&
786+
Predicate<Path> isMatchingFile = path -> (!path.equals(rootPathForPattern) &&
786787
getPathMatcher().match(resourcePattern, StringUtils.cleanPath(path.toString())));
787788

788789
if (logger.isTraceEnabled()) {

spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626
import java.util.stream.Collectors;
2727

28-
import org.junit.jupiter.api.Disabled;
2928
import org.junit.jupiter.api.Nested;
3029
import org.junit.jupiter.api.Test;
3130

@@ -100,7 +99,6 @@ void usingClasspathStarProtocol() {
10099
assertExactSubPaths(pattern, pathPrefix, "support/resource#test1.txt", "support/resource#test2.txt");
101100
}
102101

103-
@Disabled("Until gh-29333 is resolved")
104102
@Test
105103
void usingClasspathStarProtocolWithWildcardInPatternAndNotEndingInSlash() throws Exception {
106104
String pattern = "classpath*:org/springframework/core/io/sup*";
@@ -112,7 +110,6 @@ void usingClasspathStarProtocolWithWildcardInPatternAndNotEndingInSlash() throws
112110
assertThat(actualSubPaths).containsExactly("support");
113111
}
114112

115-
@Disabled("Until gh-29333 is resolved")
116113
@Test
117114
void usingFileProtocolWithWildcardInPatternAndNotEndingInSlash() throws Exception {
118115
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
@@ -148,17 +145,15 @@ void usingFileProtocolWithWildcardInPatternAndEndingInSlash() throws Exception {
148145
assertThat(actualSubPaths).isEmpty();
149146
}
150147

151-
@Disabled("Until gh-29333 is resolved")
152148
@Test
153-
void usingClasspathStarProtocolWithWildcardInPatternAndEndingWithSlashStarStar() throws Exception {
154-
String pattern = "classpath*:org/springframework/core/io/sup*/**";
149+
void usingClasspathStarProtocolWithWildcardInPatternAndEndingWithSuffixPattern() throws Exception {
150+
String pattern = "classpath*:org/springframework/core/io/sup*/*.txt";
155151
String pathPrefix = ".+org/springframework/core/io/";
156152

157153
List<String> actualSubPaths = getSubPathsIgnoringClassFilesEtc(pattern, pathPrefix);
158154

159-
// We DO find "support" if the pattern ENDS with "/**".
160155
assertThat(actualSubPaths)
161-
.containsExactlyInAnyOrder("support", "support/resource#test1.txt", "support/resource#test2.txt");
156+
.containsExactlyInAnyOrder("support/resource#test1.txt", "support/resource#test2.txt");
162157
}
163158

164159
private List<String> getSubPathsIgnoringClassFilesEtc(String pattern, String pathPrefix) throws IOException {
@@ -173,7 +168,7 @@ private List<String> getSubPathsIgnoringClassFilesEtc(String pattern, String pat
173168
}
174169

175170
@Test
176-
void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() throws Exception {
171+
void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() {
177172
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
178173
String pattern = String.format("file:%s/scanned-resources/**", testResourcesDir);
179174
String pathPrefix = ".+?resources/";
@@ -184,9 +179,8 @@ void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() throws
184179
"scanned-resources/resource#test2.txt");
185180
}
186181

187-
@Disabled("Until gh-29333 is resolved")
188182
@Test
189-
void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar() throws Exception {
183+
void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar() {
190184
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
191185
String pattern = String.format("file:%s/scanned*resources/**", testResourcesDir);
192186
String pathPrefix = ".+?resources/";

0 commit comments

Comments
 (0)