Repository navigation
fix(lexer): raw-byte tag a word-initial data ESC (niubash#200) - #474
Merged
Merged
Conversation
A raw ESC (U+001B) that reaches a word value as data - source bytes inside single/double quotes or an unquoted word, or a literal ESC character inside a $'...' span - is byte-identical to QUOTED_WORD_PREFIX, the quoted-literal- tilde marker the lexer itself emits. Downstream consumers answer strip_prefix(QUOTED_WORD_PREFIX), so a word-initial data ESC was silently eaten: printf '%s' '<ESC>[31mAAA<ESC>[0m' lost the leading ESC while the mid-string one survived (GNU bash keeps a raw ESC in every position of every quoting context). Tag a leading data ESC as the U+E000 raw-byte marker pair at both dequote choke points (word_value_from_raw and finish_word_token) - the same carrier ANSI-C decoding already uses for 0x1B - so no marker consumer can claim it; the output boundary decodes it back to the ESC byte. A mid-word ESC is never claimed (strip_prefix only fires at position 0) and stays verbatim. The quoted-tilde marker emission itself is untouched, and the textual $'\033' form already decoded to the same carrier, so it is behavior-identical. Verified byte-for-byte against GNU bash 5.2 (od -c) for single-quoted, double-quoted, unquoted, and $'...' words, plus the input-bridge boundary: this is lexer text-layer handling of script-file bytes, distinct from the niubash#434/#451 input-bridge normalization of interactive input.
caomengxuan666
added a commit
to unixwin/niubash
that referenced
this pull request
Oct 9, 2026
#200) (#235) A raw ESC byte (0x1B) as the first character inside single quotes in a script file was silently dropped by the parser, while the same byte mid-string survived; GNU bash keeps a raw ESC in every position of every quoting context. The root cause and fix live in the rubash lexer (unixwin/rubash#474): a word-initial data ESC is byte-identical to the QUOTED_WORD_PREFIX marker and was claimed by downstream strip_prefix consumers; the lexer now raw-byte tags it. These integration tests pin the product behavior byte-for-byte at the niu boundary: the issue's exact single-quote reproducer, word-initial ESC in single/double-quoted and unquoted words, ANSI-C $'\033' and mid-word spellings, the assignment storage roundtrip, and the piped-stdin entry (the niubash#434/#451 input-bridge normalization boundary - this issue is lexer text-layer handling of script bytes, not bridge normalization).
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.
Tracked by unixwin/niubash#200.
Problem
A raw ESC byte (0x1B) at the start of a word's data - most visibly as the
first character inside single quotes in a script file - was silently
dropped:
The ESC is byte-identical to
QUOTED_WORD_PREFIX(U+001B), the quoted-literal-tilde marker the lexer itself emits; executor consumers answer
strip_prefix(QUOTED_WORD_PREFIX)and claimed the data byte. Mid-wordESC bytes survived because the strip only fires at position 0. GNU bash
keeps a raw ESC in every position of every quoting context (verified
against GNU bash 5.2.37 with
od -c).Fix
tag_word_initial_raw_escat both dequote choke points(
word_value_from_raw,finish_word_token): a leading data ESC isre-encoded as the U+E000 raw-byte marker pair - the same carrier
push_ansi_c_bytealready uses for 0x1B - so no marker consumer canclaim it; the output boundary decodes it back. The quoted-tilde marker
emission is untouched; the textual
$'\033'form already decoded tothat carrier and stays byte-identical.
Tests
mid-word ESC stays verbatim;
$'<raw-ESC>'tagged and equal to$'\033'; quoted-literal-tilde marker still emittedpwd/path drive-form tests, failing on clean origin/master too)
od -coutput forsingle/double/unquoted/$'...' script cases