Skip to content

Commit

Permalink
Test for explicit URI decoding in convertClassLoaderURL
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Mar 2, 2023
1 parent f8cb0fa commit 8d112b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test 2

0 comments on commit 8d112b8

Please sign in to comment.