From b173a93e72fab22516baccbc9bb9898c54d2de81 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 28 Aug 2019 16:21:07 +0200 Subject: [PATCH] Verify PathMatchingResourcePatternResolver finds local files with # in name This commit introduces a test that verifies that PathMatchingResourcePatternResolver can find files in the filesystem that contain hashtags (#) in their names. See gh-23532 --- .../support/PathMatchingResourcePatternResolverTests.java | 8 ++++++++ .../springframework/core/io/support/resource#test1.txt | 1 + .../springframework/core/io/support/resource#test2.txt | 1 + 3 files changed, 10 insertions(+) create mode 100644 spring-core/src/test/resources/org/springframework/core/io/support/resource#test1.txt create mode 100644 spring-core/src/test/resources/org/springframework/core/io/support/resource#test2.txt 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 ade5a965596..e5821acebb9 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 @@ -16,6 +16,7 @@ package org.springframework.core.io.support; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; @@ -96,6 +97,13 @@ class PathMatchingResourcePatternResolverTests { StringUtils.concatenateStringArrays(CLASSES_IN_CORE_IO_SUPPORT, TEST_CLASSES_IN_CORE_IO_SUPPORT)); } + @Test + void getResourcesOnFileSystemContainingHashtagsInTheirFileNames() throws IOException { + Resource[] resources = resolver.getResources("classpath*:org/springframework/core/io/**/resource#test*.txt"); + assertThat(resources).extracting(Resource::getFile).extracting(File::getName) + .containsExactlyInAnyOrder("resource#test1.txt", "resource#test2.txt"); + } + @Test void classpathWithPatternInJar() throws IOException { Resource[] resources = resolver.getResources("classpath:org/reactivestreams/*.class"); diff --git a/spring-core/src/test/resources/org/springframework/core/io/support/resource#test1.txt b/spring-core/src/test/resources/org/springframework/core/io/support/resource#test1.txt new file mode 100644 index 00000000000..4f67a836c51 --- /dev/null +++ b/spring-core/src/test/resources/org/springframework/core/io/support/resource#test1.txt @@ -0,0 +1 @@ +test 1 \ No newline at end of file diff --git a/spring-core/src/test/resources/org/springframework/core/io/support/resource#test2.txt b/spring-core/src/test/resources/org/springframework/core/io/support/resource#test2.txt new file mode 100644 index 00000000000..81403e41bd3 --- /dev/null +++ b/spring-core/src/test/resources/org/springframework/core/io/support/resource#test2.txt @@ -0,0 +1 @@ +test 2 \ No newline at end of file