Repository navigation
fix: skip the indentation after a line continuation in a key - #98
Merged
Merged
Conversation
The whitespace at the start of a continued line ended the key, so "key\" followed by " part=value" was read as key "key" with the value "part=value" instead of key "keypart". An indented line with only a backslash gave an empty key. The whitespace after a line continuation is now part of the token, like in values, and is skipped when unescaping.
Collaborator
|
Another good catch! You're on fire! Thanks @wleeaf , you're help is really appreciated 👍 |
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 line continuation inside a key splits the key when the next line is indented:
The parser ends a key at the first whitespace character. After
\and the line break it is at the start of the next line, so the indentation there ends the key, and the rest of the line becomes the value. An indented line that holds only a backslash has the same problem:" \\\n beta=2\n"loads the key""with the value"beta=2"instead ofbeta=2. Values aren't affected, because whitespace doesn't end a value, andunescape()already skips the whitespace after a line continuation.addChar()now also reads the whitespace at the start of the next line after a line continuation, so it becomes part of the current token's raw text, as it already does in values.unescape()drops it as before, so the key's text iskeypartand its raw text keeps the original layout, andstore()writes the file back exactly as it was read.Tests:
TestPropertiesParser.testLineContinuationInKeychecks the tokens forkey\+ newline +part=value, andTestProperties.testLineContinuationFollowedByIndentationchecks both cases above against whatjava.util.Propertiesloads. Both fail without the change.mvn -B spotless:check packagepasses on JDK 21 (85 tests).I found this by loading 20,000 generated
.propertiesinputs with both this library andjava.util.Propertiesand comparing the results. With the change, 461 inputs that differed now match the JDK. For every input, whether thestore()round trip reloads the same map in the JDK is the same as before. One input that matched before now differs. In it, a line with only a backslash is followed by a line starting with#, which the JDK treats as a comment because the logical line is still empty. Before the change it matched only because a later line set the same key.