Split $&read return value on NUL characters.#264
Merged
jpco merged 1 commit intowryun:masterfrom Mar 29, 2026
Merged
Conversation
This should allow flexible handling of NULs - skipping them, iterating over lines split on them as fields, or throwing exceptions when encountering them. %read is implemented to skip over NULs. This should work with %parse, but avoid unexpected, rare cases where multiple elements are returned.
This was referenced Mar 28, 2026
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.
This should allow flexible handling of
NULs without having to add any unnecessary flags to$&read. By wrapping the primitive appropriately people should be able to "use" NUL bytes like to work with GNUfind -print0; they can skip them, like some other shells (bash, dash) do and like%parsewants, they can skip them but print a warning, or they can throw an exception when encountering them.%readhas been changed in initial.es so that it$&readto skip overNULs. The idea here is thatNULbytes are generally rare, so having%readonly rarely return multiple elements is probably a recipe for unpleasant surprises.This is backwards-compatibility-breaking, but there is little backwards compatibility here to consider -- until #146,
$&reading a NUL byte caused the shell to crash, and using an exception was only a stop-gap because just about anything is better than crashing. Now I think I've convinced myself that this is the best behavior for actually being able to handle NUL bytes.Some thoughts about future, follow-on changes to
$&read:$&readshould only ever split its input on NULs: performing other splitting makes the NUL-splitting ambiguous, and wrappers and callers can just use%splitor%fsplit.