From 8d112b851489ae56196c7f658f6dd9856f5cf82a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 2 Mar 2023 13:33:53 +0100 Subject: [PATCH] Test for explicit URI decoding in convertClassLoaderURL See gh-30031 --- ...PathMatchingResourcePatternResolverTests.java | 16 +++++++++++++--- .../custom#root/scanned/resource#test1.txt | 1 + .../custom#root/scanned/resource#test2.txt | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 spring-core/src/test/resources/custom#root/scanned/resource#test1.txt create mode 100644 spring-core/src/test/resources/custom#root/scanned/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 a7fb84910b6..61de1af5dce 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.FileNotFoundException; 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 java.util.stream.Collectors; 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 @@ class PathMatchingResourcePatternResolverTests { 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 00000000000..4f67a836c51 --- /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 00000000000..81403e41bd3 --- /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