Repository navigation
ConfigurationPropertyName incorrectly accepts an opening square bracket at the end of a name - #52206
Open
zhoubiao188 wants to merge 1 commit into
Conversation
…e end
ElementsParser marks the element it is building as NON_UNIFORM when a bracket
is left unterminated, which is how names such as "[bar" or "bar]" are
rejected. When the unterminated bracket is the last character of the name,
the element being built is empty and ElementsParser.add discards empty
elements, taking the NON_UNIFORM marker with it. Such names are accepted:
ConfigurationPropertyName.of("foo["); // no exception
ConfigurationPropertyName.isValid("foo["); // true
The resulting name is also inconsistent. Its only element is "foo" while
toString() is "foo[", so it is not equal to the name "foo" and does not
round-trip through ConfigurationPropertyName.of.
The unbalanced bracket is now included in the final element so that it is
not dropped as an empty element and the name is reported as invalid, which
is already the case for "foo[bar".
Signed-off-by: zhoubiao188 <32508238+zhoubiao188@users.noreply.github.com>
This branch has not been deployed
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.
ConfigurationPropertyNamerejects names with a bracket that is left unterminated.ElementsParser.parserecords this by marking the element it is currently building asNON_UNIFORM, andelementsOfrejects any name that contains aNON_UNIFORMelement:When the unbalanced bracket is the last character of the name, the element being
built is empty and
adddiscards empty elements, taking theNON_UNIFORMmarker withit. Such names are accepted:
while the equivalent names with content are correctly rejected:
The accepted name is also self-inconsistent. Its only element is
foo, buttoString()returns
foo[(the source is used as a shortcut), so it is not equal to the namefooand it does not round-trip through
ConfigurationPropertyName.of.With this change the unbalanced bracket is included in the final element so that it is
not dropped as an empty element, and the name is reported as invalid — the same outcome
as for
foo[bar:InvalidConfigurationPropertyNameException.getInvalidCharacters()reports[, whichmatches the existing behaviour for
[bar.Regression tests are included for
foo[, for the name consisting of just[, and forisValid. Without the fix these fail; with it they pass. The rest of theorg.springframework.boot.context.propertiestest tree is unaffected.