Skip to content

Commit 8d112b8

Browse files
committed
Test for explicit URI decoding in convertClassLoaderURL
See gh-30031
1 parent f8cb0fa commit 8d112b8

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.UncheckedIOException;
2222
import java.net.URL;
23+
import java.net.URLClassLoader;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
2526
import java.util.Arrays;
@@ -29,6 +30,7 @@
2930
import org.junit.jupiter.api.Nested;
3031
import org.junit.jupiter.api.Test;
3132

33+
import org.springframework.core.io.DefaultResourceLoader;
3234
import org.springframework.core.io.FileSystemResource;
3335
import org.springframework.core.io.Resource;
3436
import org.springframework.util.StringUtils;
@@ -59,7 +61,7 @@ class PathMatchingResourcePatternResolverTests {
5961
private static final String[] CLASSES_IN_REACTOR_UTIL_ANNOTATION = { "NonNull.class", "NonNullApi.class", "Nullable.class" };
6062

6163

62-
private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
64+
private PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
6365

6466

6567
@Nested
@@ -88,8 +90,16 @@ void classpathStarWithPatternOnFileSystem() {
8890
assertFilenames(pattern, expectedFilenames);
8991
}
9092

93+
@Test
94+
void encodedHashtagInPath() throws IOException {
95+
Path rootDir = Paths.get("src/test/resources/custom%23root").toAbsolutePath();
96+
URL root = new URL("file:" + rootDir + "/");
97+
resolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader(new URLClassLoader(new URL[] {root})));
98+
assertExactFilenames("classpath*:scanned/*.txt", "resource#test1.txt", "resource#test2.txt");
99+
}
100+
91101
@Nested
92-
class WithHashtagsInTheirFileNames {
102+
class WithHashtagsInTheirFilenames {
93103

94104
@Test
95105
void usingClasspathStarProtocol() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test 2

0 commit comments

Comments
 (0)