-
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
Cannot serve static resources with spaces from "file:" location when using PathPattern
and UrlPathHelper is set to not decode
#27791
Comments
Thanks for the report and sample application, I've reproduced the problem. As far as I can tell, this appears to be a bug in Spring Framework. In the case where it works, Could you please take a look, @bclozel? |
Also please note this bug affects not only files with spaces in the name, but files with non-ASCII characters such as |
This almost look like a duplicate of #26775. While this case is in theory covered by I think that this last bit is incorrect - in the case of a Spring MVC application using the @rstoyanchev do you think this analysis is right? If so, I'm going to move this issue back to Spring Boot update the |
The settings of I think I can see the issue in I'll experiment with a test and a fix. |
AntPathMatcher
to PathPattern
PathPattern
and UrlPathHelper is set to not decode
Description
After upgrading from Spring Boot 2.5.6 to 2.6.1, I've detected a behaviour change affecting access to static files with "special chars" in file names(spaces, accents, etc.)
I believe this is related to the change from AntPathMatcher to PathPattern introduced in Spring Boot 2.6.0-M3.
When I try to serve static files from a custom location from my filesystem (outside the default static paths configured by Spring Boot), I can not access files with spaces (or accents) in file names.
I've prepared a sample project to demonstrate this behavior. My only customization is adding a new resource handler to be able to access static files under the
/tmp/repo
directory:Steps to reproduce
Once the app is running, try to access the static file
foo bar.txt
under resources/static and /tmp/repo:http://localhost:8080/foo%20bar.txt (this works fine)
http://localhost:8080/repo/foo%20bar.txt (this returns error 404)
The only difference is that the first URL is getting a file located at
src/main/resources/static/
(this directory is preconfigured by default via Spring Boot to serve static files), and the second URL is trying to get a file located atfile:/tmp/repo
, configured manually via my @configuration class usingaddResourcehandler
/addResouceLocations
.The interesting thing is that this second URL works perfectly (returns the file) when using Spring Boot 2.5.7 instead of 2.6.1 (you can try changing the version in
pom.xml
and restarting the app).Workaround
As a workaround, I can force the old behavior by setting the following property in my
application.properties
:With this configuration, the second URL works fine again, as it did with Spring Boot 2.5.x.
The text was updated successfully, but these errors were encountered: