Fix extract_key to match bash double-quote escape grammar#6
Merged
Conversation
extract_key previously consumed every backslash as an escape and dropped it, so hand-edited values like USER="abc\xyz" (where \x is not in bash's recognized escape set) silently lost the backslash on migration. Match bash semantics: only consume the backslash when followed by \, ", $, or backtick; otherwise preserve it literally.
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.
extract_key in helpers/migrate-config.sh unconditionally treated backslash as an escape and dropped it, even when followed by a character that bash itself preserves literally (e.g.
\\x). A hand-editedUSER="abc\\xyz"round-tripping through migration would silently turn intoabcxyz.Bash's double-quoted-string grammar only recognises
\\followed by\\,",$, or backtick — for any other character, the backslash is preserved. The parser now matches that, so the migrated file sources to the same value as the original.In practice this only matters for hand-edited boot configs since MLAT_USER is constrained to
^[A-Za-z0-9_-]{1,64}$everywhere else. Three new test cases cover the literal-backslash preserve path, the recognised-escape collapse path, and the escaped-close-quote-with-no-real-close malformed verdict.