fix: escape leading # and ! in keys so they round-trip - #22
Open
mahirhir wants to merge 2 commits into
Open
Conversation
A key starting with # or ! was written out unescaped, so parse() read the line back as a comment and dropped the entry. escapeKey already escapes the separator characters (space, =, :); escape a leading # or ! as well so such keys survive a round trip, matching java.util.Properties.
eemeli
requested changes
Jun 30, 2026
eemeli
left a comment
Owner
There was a problem hiding this comment.
Looks good, thank you for catching this!
See inline for a small tweak.
Comment on lines
+16
to
+17
| const escapeKey = key => | ||
| escape(key).replace(/[ =:]/g, '\\$&').replace(/^[#!]/, '\\$&') |
Owner
There was a problem hiding this comment.
This should work as well?
Suggested change
| const escapeKey = key => | |
| escape(key).replace(/[ =:]/g, '\\$&').replace(/^[#!]/, '\\$&') | |
| const escapeKey = key => escape(key).replace(/^[#!]|[ =:]/g, '\\$&') |
Author
|
Applied, thanks. Full suite still 100% coverage, 40/40 passing. |
eemeli
approved these changes
Jul 12, 2026
eemeli
left a comment
Owner
There was a problem hiding this comment.
Please fix the code style, and this is good to merge.
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.
stringifydoes not escape a#or!at the start of a key. Since those characters start a comment when they lead a line,parsereads the output back as a comment and drops the pair:escapeKeyalready escapes the separator characters (space,=,:) so they survive a round trip. The comment markers have the same problem when they lead a key, so I escape a leading#or!there too.parsealready unescapes\#/\!back to#/!, andjava.util.Propertiesescapes these as well, so the result round-trips and stays consistent with the reference format. They are left untouched elsewhere in the key, since they are only special at the start of a line.Added a round-trip test in
tests/corner-cases.tests.js. The full suite (40 tests, 100% coverage), eslint, and prettier all pass.