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 a7fb84910b68..61de1af5dce8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; @@ -29,6 +30,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.util.StringUtils; @@ -59,7 +61,7 @@ class PathMatchingResourcePatternResolverTests { private static final String[] CLASSES_IN_REACTOR_UTIL_ANNOTATION = { "NonNull.class", "NonNullApi.class", "Nullable.class" }; - private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + private PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); @Nested @@ -88,8 +90,16 @@ void classpathStarWithPatternOnFileSystem() { assertFilenames(pattern, expectedFilenames); } + @Test + void encodedHashtagInPath() throws IOException { + Path rootDir = Paths.get("src/test/resources/custom%23root").toAbsolutePath(); + URL root = new URL("file:" + rootDir + "/"); + resolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader(new URLClassLoader(new URL[] {root}))); + assertExactFilenames("classpath*:scanned/*.txt", "resource#test1.txt", "resource#test2.txt"); + } + @Nested - class WithHashtagsInTheirFileNames { + class WithHashtagsInTheirFilenames { @Test void usingClasspathStarProtocol() { diff --git a/spring-core/src/test/resources/custom#root/scanned/resource#test1.txt b/spring-core/src/test/resources/custom#root/scanned/resource#test1.txt new file mode 100644 index 000000000000..4f67a836c51f --- /dev/null +++ b/spring-core/src/test/resources/custom#root/scanned/resource#test1.txt @@ -0,0 +1 @@ +test 1 \ No newline at end of file diff --git a/spring-core/src/test/resources/custom#root/scanned/resource#test2.txt b/spring-core/src/test/resources/custom#root/scanned/resource#test2.txt new file mode 100644 index 000000000000..81403e41bd36 --- /dev/null +++ b/spring-core/src/test/resources/custom#root/scanned/resource#test2.txt @@ -0,0 +1 @@ +test 2 \ No newline at end of file