-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Add support for double backslashes to StringUtils#cleanPath
#32962
Comments
Hi, I am not on Windows but what likely happens is that:
Even if this double backslash comes from a (kind of surprising to me) Maven feature enabled by default, the fact that |
StringUtils#cleanPath
Based on https://en.wikipedia.org/wiki/File_URI_scheme, it should not be needed to support the leading @floringolintchi Please check your repro is fine on Windows with Spring Framework |
@sdeleuze Tried it in test project and it works fine now, thank you for the fix. 🍻 |
This change has broken the ability to use a network path as a URI in windows. eg. if we want to access a path such as Now it is always failing due to the path being "cleaned" as |
@stevo-devo, since this issue is closed (with the changes released in 6.1.9), can you please create a new issue to report the regression you are experiencing? |
Affects: 6.1.8
While upgrading a project from spring boot 3.1.12 to spring boot 3.2.6 I've encountered issues with my
@Value
injection path to system file on my Windows machine being rebuilt incorrectly byStringUtils.cleanPath(...)
. I believe this concerns the way Spring handles\
characters when loading maven properties inapplication.yml
. I've created a demo I'll attach showcasing the issue.My file is loaded like this:
where the property in
application.yml
looks like this:path.to.a.file: file:@path.to.a.key.file@
the maven property referenced is:
(the original project is a multi-module project)
From my testing this is related to the change to https://github.com/spring-projects/spring-framework/blob/v6.1.8/spring-core/src/main/java/org/springframework/util/ResourceUtils.java#L412
in previous major version this would build directly without any changes to location:
https://github.com/spring-projects/spring-framework/blob/v6.0.21/spring-core/src/main/java/org/springframework/util/ResourceUtils.java#L419
I don't think this is an issue with
StringUtils.cleanPath(...)
, but with the fact that Spring will inject this maven property with double\\
, rather than just one\
. Example images from the demo project I have attached, howapplication.yml
looks like in target folder:And debugging, what the String is equal to since I was confused by the IntelliJ output:
how
cleanPath
outputs the wrong path when given input with double\
:after removing one escaped
\
,cleanPath
works as expected:From what I can tell maven won't use double backslashes so these are added by Spring I believe (output of maven command to check how properties look like):
Here is the stack trace:
This can easily be fixed by editing the string with SpEL:
@Value("#{'${path.to.a.file}'.replace('\\\\', '\\')}")
or just telling maven to add the files to my classpath, but I am opening this in case this is an issue worth considering, I apologize otherwise.Demo project: demo_resourceUtils_issue.zip
The text was updated successfully, but these errors were encountered: