8000 Escaped placeholders are evaluated if the PropertySource has placeholder support · Issue #34326 · spring-projects/spring-framework · GitHub
[go: up one dir, main page]

Skip to content

Escaped placeholders are evaluated if the PropertySource has placeholder support #34326

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

Closed
snicoll opened this issue Jan 27, 2025 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@snicoll
Copy link
Member
snicoll commented Jan 27, 2025

This is a follow-up of #34315

Consider the following example:

prop1=value1
prop2=value2\\${prop1}

prop2 should evaluate to value2${prop1} as the placeholder has been escaped.

This works for basic PropertySource implementations, but if the source is backed by PropertySourcesPlaceholderConfigurer the escaped ${prop1} is still evaluated even though it should not be.

@snicoll snicoll added the type: bug A general bug label Jan 27, 2025
@snicoll snicoll added this to the 6.2.x milestone Jan 27, 2025
@snicoll snicoll self-assigned this Jan 27, 2025
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 28, 2025
@snicoll
Copy link
Member Author
snicoll commented Feb 3, 2025

So the problem is that PropertySourcesPropertyResolver contains a nested PlaceholderResolver itself. When prop2 is requested, it goes to a first round where it is resolved to value2\\${prop1} which is then parsed as value2${prop1} where the escaped character is removed and ${prop1} is considered as a litteral string.

The problem is that this resolved value come back to the original parser. Rather than seeing value2\\${prop1} it gets value2${prop1} and it resolves the nested placeholder since it has lost its escape character.

@sbrannen
Copy link
Member
sbrannen commented May 7, 2025

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2025
@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label May 7, 2025
@sbrannen sbrannen removed this from the 6.2.7 milestone May 7, 2025
sbrannen pushed a commit that referenced this issue May 9, 2025
See gh-34326
See gh-34720
See gh-34861

Signed-off-by: Fawzi Essam <iifawzie@gmail.com>
sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 10, 2025
Currently, the placeholder resolution algorithm in
PropertySourcesPlaceholderConfigurer fails in several scenarios, and
the root cause for this category of failures has actually existed since
PropertySourcesPlaceholderConfigurer was introduced in Spring Framework
3.1.

Specifically, PropertySourcesPlaceholderConfigurer creates its own
PropertySourcesPropertyResolver that indirectly delegates to another
"nested" PropertySourcesPropertyResolver to interact with
PropertySources from the Environment, which results in double
placeholder parsing and resolution attempts, and that behavior leads to
a whole category of bugs.

For example, spring-projects#27947 was addressed in Spring Framework 5.3.16, and due
to spring-projects#34315 and spring-projects#34326 we have recently realized that additional bugs
exist with placeholder resolution: nested placeholder resolution can
fail when escape characters are used, and it is currently impossible
to disable the escape character support for nested resolution.

To address this category of bugs, we no longer indirectly use or
directly create a "nested" PropertySourcesPropertyResolver in
PropertySourcesPlaceholderConfigurer. Instead, properties from property
sources from the Environment are now accessed directly without
duplicate/nested placeholder resolution.

See spring-projectsgh-27947
See spring-projectsgh-34326
See spring-projectsgh-34862
Closes spring-projectsgh-34861
sbrannen added a commit that referenced this issue May 10, 2025
Currently, the placeholder resolution algorithm in
PropertySourcesPlaceholderConfigurer fails in several scenarios, and
the root cause for this category of failures has actually existed since
PropertySourcesPlaceholderConfigurer was introduced in Spring Framework
3.1.

Specifically, PropertySourcesPlaceholderConfigurer creates its own
PropertySourcesPropertyResolver that indirectly delegates to another
"nested" PropertySourcesPropertyResolver to interact with
PropertySources from the Environment, which results in double
placeholder parsing and resolution attempts, and that behavior leads to
a whole category of bugs.

For example, #27947 was addressed in Spring Framework 5.3.16, and due
to #34315 and #34326 we have recently realized that additional bugs
exist with placeholder resolution: nested placeholder resolution can
fail when escape characters are used, and it is currently impossible
to disable the escape character support for nested resolution.

To address this category of bugs, we no longer indirectly use or
directly create a "nested" PropertySourcesPropertyResolver in
PropertySourcesPlaceholderConfigurer. Instead, properties from property
sources from the Environment are now accessed directly without
duplicate/nested placeholder resolution.

See gh-27947
See gh-34326
See gh-34862
Closes gh-34861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0