dxbjavid opened a new pull request, #797:
URL: https://github.com/apache/commons-text/pull/797
With `setEnableSubstitutionInVariables(true)`, `StringSubstitutor`
substitutes an escaped variable whose name starts with a nested variable
whenever no later `}` follows it in the input. With `a=1` and `1=one`,
`$${${a}}` returns `one`, while `$${${a}} ${a}` returns `${1} 1`. The
deprecated `StrSubstitutor` returns `${1}` in both cases.
The cause is in `substitute`: after deleting the escape it moves `pos` back
to the escape position when the escaped name starts with a prefix and
`hasLaterSuffix` finds nothing. That rescan is there for the default mode,
where the first suffix found may be the inner one (`$${${a}` stays `${${a}`).
In nested mode the suffix found is already the balanced outer one, so the
rescan reads the escaped expression again and resolves it. The fix skips the
rescan when substitution in variables is enabled. Default-mode behaviour is
unchanged.
This matters when a template escapes an expression so that it comes out
literally and the inner value is not trusted. For example, with
`StringLookupFactory.INSTANCE.interpolatorStringLookup(map)` and
`user=file:UTF-8:LICENSE.txt`, `$${${user}}` returns the contents of
LICENSE.txt instead of `${file:UTF-8:LICENSE.txt}`.
`StringSubstitutorTest#testReplaceInVariableEscaped` fails without the
change to `StringSubstitutor` (`expected: <${1}> but was: <one>`) and passes
with it. The default `mvn` build passes (2045 tests; Checkstyle, PMD, SpotBugs
and Javadoc are clean).
---
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]