fix: escape backslashes in set_key so values round-trip#662
Open
Noethix55555 wants to merge 1 commit into
Open
fix: escape backslashes in set_key so values round-trip#662Noethix55555 wants to merge 1 commit into
Noethix55555 wants to merge 1 commit into
Conversation
set_key wrote single-quoted values escaping only single quotes, but the single-quoted-value parser treats backslash as an escape character. Values containing backslashes (Windows paths like C:\Users, regexes like \d+) were therefore corrupted when read back via get_key. Escape backslashes before single quotes so the written value round-trips. Closes theskumar#661
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.
Summary
set_keywrites single-quoted values but only escapes single quotes, not backslashes. Because the single-quoted-value parser treats\as an escape character (decoding\\->\and\'->'), any value containing a backslash is corrupted on round-trip throughget_key.This affects Windows paths and regular expressions in particular.
Fix
Escape backslashes before escaping single quotes in
set_key:This mirrors how the parser unescapes values, so writes round-trip.
Tests
Added a parametrized round-trip regression test (
test_set_key_roundtrip_with_backslashes) coveringC:\Users,\d+,\,a\b,a\\b, and a backslash+quote combination. Verified it fails onmainand passes with the fix. The existingtest_set_keycases and the rest of the suite remain green.Closes #661