Skip to content

Fix extract_key to match bash double-quote escape grammar#6

Merged
d4rken merged 2 commits into
devfrom
fix/extract-key-backslash-grammar
May 12, 2026
Merged

Fix extract_key to match bash double-quote escape grammar#6
d4rken merged 2 commits into
devfrom
fix/extract-key-backslash-grammar

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented May 12, 2026

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-edited USER="abc\\xyz" round-tripping through migration would silently turn into abcxyz.

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.

d4rken added 2 commits May 12, 2026 10:11
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.
@d4rken d4rken merged commit 2295466 into dev May 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant