-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PathMatchingResourcePatternResolver cannot load resources with a '#' in their file name within JARs #23532
Comments
Thanks for raising the issue. As an interim solution, is it possible for you to rename the JSON files so that they do not contain hash tags (i.e., Also, where does After a bit of research, I assume you're referring to |
Are your JSON files always in JAR files? If so, have you tried the following? Resource[] resources = resourceLoader.getResources("classpath*:/validation/**/api%23test.json"); |
I've edited this issue to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. |
…n 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
FYI: b173a93 demonstrates that |
<1-1>ParseUtil is sun.net.www.ParseUtil. java.net.URLEncoder.encode() is OK! <1-2>java.net.JarURLConnection private void parseSpecs(URL url) throws MalformedURLException {
....
// ***** use ParseUtil ******
entryName = ParseUtil.decode (entryName);
...
} <1-3>I found that the spring boot also has a JarUrlConnection, and there is also a decoding function in the guess.
That does not work PathMatchingResourcePatternResolver method protected Set<Resource> doFindPathMatchingJarResources()
···
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (entryPath.startsWith(rootEntryPath)) {
String relativePath = entryPath.substring(rootEntryPath.length());
// ****** Unable to match escaped *****
if (getPathMatcher().match(subPattern, relativePath)) {
result.add(rootDirResource.createRelative(relativePath));
}
}
}
···
It is OK when in the file system the processing logic of jar and file is not the same. When dealing with url, I did not carefully look at the source code to analyze the difference between jar and file
|
@tofdragon Could you give us a demo code which can reproduce the bug? |
@lgxbslgx Please see the problem description |
Affects: spring version 5.1.5
Description
Given file
/validation/api#test.json
withina.jar
which is in the classpath...a project dependent a.jar, in project code
error:
Analysis
The
URL
created inorg.springframework.core.io.UrlResource.createRelative(String)
treats everything after#
as the URL fragment, causing the file path to be incorrect when the file is last read.URL object:
a.jar!/validation/api
a.jar!/validation/api
test.json
Solutions
Solution 1
Solution 2
Question
Is there any other better solution, or is there a problem with my use?
The text was updated successfully, but these errors were encountered: