-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Escaping logic in PlaceholderParser does not handle escaped backslashes #34315
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
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 backslash 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. |
@bitb4ker is right, that's a breaking change. You should at least mention it in the release notes. |
@neoludo Can you suggest what's missing from the release notes? |
That sentence But in yaml file, and given that yaml snippet : So there is no need to move backslashes to value itself and release note should dissociate yaml parsing from properties parsing |
I guess this is a Yaml specific concern; but I guess the advice to move the "" directly into one of the values still applies. |
@bclozel I see a paragraph was added on that in the release notes however I still think that this is an issue that needs to be addressed as being forced to add the \ in the value being interpolated is just not right. Could we add implement an escape mechanism for the escape character somewhere in the roadmap? |
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: