Repository navigation
fix: don't treat backslashes in comments as escapes - #96
Merged
Merged
Conversation
The parser handled escape sequences in every token, including comments.
In java.util.Properties a backslash has no special meaning in a comment
line, and a comment line can't be continued. Here a comment with a
Windows path made loading fail ("# C:\users" is read as a malformed
\uXXXX escape), and a comment ending with a backslash swallowed the
next line, so the property on it was lost:
# temp dir: C:\temp\
alpha=1
Comments are now read as they are, up to the end of the line.
Collaborator
|
Great catch, thanks for your help @wleeaf ! |
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.
PropertiesParserprocesses escape sequences in every token, comments included. Injava.util.Properties, a backslash in a comment line has no special meaning, and a comment line can't be continued onto the next line. Two things go wrong here because of that.A comment containing something like a Windows path makes loading fail, because
\ustarts a\uXXXXescape:A comment that ends with a backslash is treated as a line continuation, so the next line becomes part of the comment and its property is lost:
loadPropertiesreturns noalphahere, whilejava.util.Propertiesloadsalpha=1from both files.addChar()now skips escape handling while reading aCOMMENTtoken, so a comment runs up to the end of its line as written. This also meansgetPropertyComment()returns such comments as they appear in the file, instead of with\tand similar sequences decoded.Tests:
TestPropertiesParser.testBackslashesInCommentchecks the tokens for a comment with\users\followed by a property, andTestProperties.testCommentEndingWithBackslashchecks that the property after such a comment is loaded. Both fail without the change.mvn -B spotless:check packagepasses on JDK 21 (82 tests).I found this by loading 20,000 generated
.propertiesinputs with both this library andjava.util.Propertiesand comparing the results. With this change, the inputs where only this parser fails drop from 242 to 13, and 463 more inputs give the same result as the JDK. 11 inputs that matched before only because the comment swallowed the next line now differ. In each of them that next line is a lone\, which this parser reads differently from the JDK (a separate issue).