Repository navigation
OriginTrackedPropertiesLoader drops the line following a comment that ends with a backslash - #52270
Open
zhoubiao188 wants to merge 1 commit into
Conversation
`OriginTrackedPropertiesLoader#isNewDocument` reads ahead through a comment to work out whether it is a document separator. Those reads went through `CharacterReader#read()` which treats a trailing backslash as a line continuation, so a comment such as `#\`, `#a\` or `#---\` continued reading on the following line. The reader therefore ended up past the end of the comment line and `skipComment()` dropped the property on that line. The remaining characters of the comment are now read without handling escape sequences so that the look-ahead can never cross the line boundary. This matches `java.util.Properties`, where a trailing backslash has no special meaning inside a comment. 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.
A comment line that ends with a backslash causes the property on the next line to be silently dropped. For example, this file
loads no properties at all, whereas
java.util.Propertiesloadskey=value.Cause
isNewDocumentlooks ahead through a comment to work out whether it is a---document separator. The look-ahead usesCharacterReader#read(), which treats a trailing backslash as a line continuation and carries on reading on the following line. The reader therefore ends up past the end of the comment line andskipComment()discards the rest of the following line, losing the property.Fix
The remainder of the comment line is now inspected with a new
CharacterReader#readRaw()that does not process escape sequences, so the look-ahead can never cross the line boundary. This matchesjava.util.Properties, where a trailing backslash has no special meaning inside a comment.Verification
loadWhenCommentEndsWithBackslashLoadsFollowingProperties,loadWhenCommentWithExclamationPrefixEndsWithBackslashLoadsFollowingPropertiesandloadWhenDocumentSeparatorEndsWithBackslashLoadsSingleDocument. The first two fail without the change; the third one covers#---\, whereb=bwas previously swallowed as well.java.util.Propertiesover 100000 generated small properties files: 98 inputs that previously disagreed now match, and no input that previously matched now disagrees.:core:spring-boot:checkFormat,checkstyleMain,checkstyleTestand theorg.springframework.boot.envtests pass (43 tests inOriginTrackedPropertiesLoaderTests).