-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null character (i.e. "\0") terminates string, but should actually be escaped instead #212
Comments
Which shell are you using? (I don't think it's csh) I see: $ echo $'hello \0 world' | od -cb
0000000 h e l l o \n
150 145 154 154 157 040 012
0000007 In a bash and in a sh. Be that as it may, the |
Oh, I forgot-- IIRC command line arguments on Mac/Linux are C-strings, so a But, jo still has this problem when a shell isn't involved, though. See: % echo $'hello \0 world' > hw.txt
% od -cb hw.txt
0000000 h e l l o \0 w o r l d \n
150 145 154 154 157 040 000 040 167 157 162 154 144 012
0000016
% jo greeting=@hw.txt
{"greeting":"hello "} In any case, if zero bytes aren't being handled correctly internally, then there's nothing that can be done, I guess. It's a shame to not support UTF-8 correctly, though. |
I'd still like to know which shell you're using: $ echo $'hello \0 world' > hw.txt
$ od -cb hw.txt
0000000 h e l l o \n
150 145 154 154 157 040 012
0000007 |
zsh on MacOS Sonoma % $SHELL --version
zsh 5.9 (x86_64-apple-darwin23.0) |
That explains it. From the
As for dealing with embedded null characters, that's a massive change, involving adding the concept of counted strings all through the current C codebase. Given that zsh's default treatment of null characters seems to be an outlier rather than the norm among command-line shells, making the huge effort to support embedded nulls will inevitably lead to a different set of issues raised here, viz. "you can't get there (embedded nulls) from here (your current shell, except zsh)". |
I get that. I would make a few points, however:
% cat nb.json
{"nb": "\u0000"}
% jo fileContents=:nb.json
jo: Cannot decode JSON in file nb.json |
My understanding of the JSON spec is that the null character (
\0
) is a perfectly cromulent character in an JSON string because JSON strings are UTF-8.A null character in a string apparently terminates the string in jo:
Other control control characters get escaped correctly:
It's not a problem with the shell handling
\0
because this works as expected:The text was updated successfully, but these errors were encountered: