Repository navigation
Conversation
With setEnableSubstitutionInVariables(true), StringSubstitutor resolved
an escaped variable whose name starts with a nested variable, such as
$${${a}}, whenever no later suffix followed it in the input. The rescan
from the escape position is only needed in the default mode, where the
first suffix found may be the inner one; in nested mode it re-reads the
escaped expression and substitutes it. StrSubstitutor returns ${1} for
the same input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
setEnableSubstitutionInVariables(true),StringSubstitutorsubstitutes an escaped variable whose name starts with a nested variable whenever no later}follows it in the input. Witha=1and1=one,$${${a}}returnsone, while$${${a}} ${a}returns${1} 1. The deprecatedStrSubstitutorreturns${1}in both cases.The cause is in
substitute: after deleting the escape it movesposback to the escape position when the escaped name starts with a prefix andhasLaterSuffixfinds 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)anduser=file:UTF-8:LICENSE.txt,$${${user}}returns the contents of LICENSE.txt instead of${file:UTF-8:LICENSE.txt}.StringSubstitutorTest#testReplaceInVariableEscapedfails without the change toStringSubstitutor(expected: <${1}> but was: <one>) and passes with it. The defaultmvnbuild passes (2045 tests; Checkstyle, PMD, SpotBugs and Javadoc are clean).mvn; that'smvnon the command line by itself.