Repository navigation
End ANSI-C strings at the first NUL escape - #17
Merged
Merged
Conversation
webpro
approved these changes
Oct 23, 2026
webpro
left a comment
Member
There was a problem hiding this comment.
Thanks, Mantas! I checked this against Bash 5.3 and the new values match for every NUL-producing escape I tried, including \x0, \c followed by a backtick or a space, and a NUL right after pending UTF-8 bytes. The read -r -d $'\0' in git-completion.bash and the $'\0' comparison in acme.sh from our fixtures now get "", as in Bash, and the parse path shows no measurable cost. Heredoc delimiters go through the same decoder, so cat <<$'E\0X' now closes on a line E, as Bash does, instead of swallowing the rest of the script. I pushed a test for that case.
Member
|
🚀 This pull request is included in v6.0.2. See Release 6.0.2 for release notes. |
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.
Bash ends a
$'...'string at the first NUL that an escape produces (\0,\x00,\400,\c@,\U00000000). The rest of the quoted text is dropped, and text after the closing quote still joins the word.decodeAnsiCQuotedkept the NUL and everything after it invalue:Word.valuebeforeread -r -d $'\0' file''"\x00"""$'a\0b'cac"a\x00bc""ac"$'\c@x'''"\x00x"""$'\U00000000y'''"\x00y"""read -d $'\0'andmapfile -d $'\0'get the same empty string from Bash as-d ''.Change
The decoder records where the first escape-produced NUL lands and cuts
valuethere after scanning to the closing quote, soend,text,closedand the rest of the word are unchanged. A\coperand outside ASCII keeps its current decoding.Tests
New test in
test/word-parts.test.tswith values checked against Bash 5.3.20; it fails before the change and passes after.pnpm lint,pnpm test,pnpm test:typesandnode test/runtime.mjson Node 14 pass.