Repository navigation
fix: drop a backslash at the end of the input - #97
Merged
Merged
Conversation
When the input ended with a backslash, the parser read the end of the stream (-1) as the escaped character and stored it as '\uffff'. So "foo=bar\" at the end of a file without a final newline loaded as "bar\uffff", and a key ending there got the same extra character. java.util.Properties drops such a backslash and loads "bar". The trailing backslash now stays in the raw text, so the file is written back unchanged, but it is left out of the key or value.
Collaborator
|
Oh wow, good catch! 👍 |
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.
When the input ends with a backslash (for example, the last line of a file without a final newline ends in a line continuation),
addChar()reads the end of the stream as the escaped character. It stores(char) -1, which is'�':A key ending there gets the same extra character (
"foo\\"loads the key"foo�").java.util.Propertiesdrops such a backslash and loads"bar"and"foo".addChar()now returns without appending anything when the character after a backslash is the end of the input, andunescape()ignores a trailing lone backslash. The backslash stays in the raw text, sostore()still writes the file back exactly as it was read.Test:
TestPropertiesParser.testBackslashAtEofchecks thatfoo=bar\at the end of the input gives the value textbarwith the raw textbar\. It fails without the change.mvn -B spotless:check packagepasses on JDK 21 (81 tests).I found this by loading 20,000 generated
.propertiesinputs with both this library andjava.util.Propertiesand comparing the results. 114 inputs that differed now match the JDK, and none that matched before differ now.