diff --git a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java index ec92d54dcb3..ec0dffa9884 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java @@ -66,7 +66,6 @@ class PathMatchingResourcePatternResolverTests { void invalidPrefixWithPatternElementInItThrowsException() { assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> resolver.getResources("xx**:**/*.xy")); } - } @@ -107,6 +106,21 @@ class PathMatchingResourcePatternResolverTests { assertExactFilenames(pattern, "resource#test1.txt", "resource#test2.txt"); assertExactSubPaths(pattern, pathPrefix, "resource#test1.txt", "resource#test2.txt"); } + + @Test + void usingFileProtocolAndAssertingUrlAndUriSyntax() throws Exception { + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); + String pattern = "file:%s/scanned-resources/**/resource#test1.txt".formatted(testResourcesDir); + Resource[] resources = resolver.getResources(pattern); + assertThat(resources).hasSize(1); + Resource resource = resources[0]; + assertThat(resource.getFilename()).isEqualTo("resource#test1.txt"); + // The following assertions serve as regression tests for the lack of the + // "authority component" (//) in the returned URI/URL. For example, we are + // expecting file:/my/path (or file:/C:/My/Path) instead of file:///my/path. + assertThat(resource.getURL().toString()).matches("^file:\\/[^\\/].+test1\\.txt$"); + assertThat(resource.getURI().toString()).matches("^file:\\/[^\\/].+test1\\.txt$"); + } } }