-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Escaping logic in PlaceholderParser does not handle escaped backslashes #34315
Comments
The parser in 6.2 has been rewritten to fix, amongst other things, #9628. Unfortunately, this means that if the placeholder is escaped, it's rendered as is (i.e. not evaluated). I wrote a test: @Test
void gh34315() {
Properties properties = new Properties();
properties.setProperty("prop1", "value1");
properties.setProperty("prop2", "value2\\${prop1}");
PlaceholderParser parser = new PlaceholderParser("${", "}", ":", '\\', true);
assertThat(parser.replacePlaceholders("${prop2}", properties::getProperty)).isEqualTo("value2${prop1}");
} and it passes. I've also added those two properties in an empty Spring 6.2 app and it resolved the same way. Can you share a sample that actually fails the way you've described? |
To run:
The 3.3 one shows the expected behavior, the 3.4 shows what I described as the broken behavior in both '\' and '\\' in the original post. |
I got it now. The problem is |
The issue as reported can't be fixed without re-introducing the bug that we fixed. The side effect that was found as part of the report is going to be handled by #34326. For that case above, you'll need to restructure your configuration to move the backlash elsewhere to avoid the escaping, something like:
|
Couldn't we introduce a way to escape the escape character? |
Everything is possible, I guess but we’re not keen to make the parser more complex at this time. |
My issue is that this broke something that was working for years. |
Up until spring-boot 3.3.8, and escaped backslash followed by a placeholder like:
Was resulting prop2 resolving to:
Starting with spring-boot 3.4.0, the result is:
Doubling the backslashes like this:
Results in:
This is due to the escaping logic introduced in
org.springframework.util.org.springframework.util.PlaceholderParser
which does two passes ofPlaceholderParser.SimplePlaceholderPart.resolveRecursively(PartResolutionContext, String)
, each callingPlaceholderParser.parse(String, boolean)
in which the escaping logic is implemented.This last method does not handle escaping the escape character, causing the issue.
The text was updated successfully, but these errors were encountered: