zsh-workers
 help / color / mirror / code / Atom feed
* expr length "$val" returns the wrong length for values containing NULL (\\0)
@ 2015-12-10  1:52 D Gowers
  2015-12-10  3:56 ` Nikolay Aleksandrovich Pavlov (ZyX)
  0 siblings, 1 reply; 7+ messages in thread
From: D Gowers @ 2015-12-10  1:52 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 639 bytes --]

Test case:

v=$(printf foo\\0bar);expr length "$v";expr length $v

alternatively:

v=foo$'\0'bar;expr length "$v";expr length $v

In zsh, the values returned are  3 and 3.
In dash and zsh, the values returned are 6 and 6.

Both of those results are wrong, AFAICS (foo$'0'bar is 7 characters long).
But the zsh result is more severely wrong. I could understand the bash/dash
result, at least,  as 'NULL characters are not counted towards length'.

In any case, it is easily demonstrated that the string is not 3 characters
long, by running 'echo "$V"' or 'print "$v"' or 'echo ${#v}'

`zsh --version` = 'zsh 5.2 (x86_64-unknown-linux-gnu)'

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-12-10 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-10  1:52 expr length "$val" returns the wrong length for values containing NULL (\\0) D Gowers
2015-12-10  3:56 ` Nikolay Aleksandrovich Pavlov (ZyX)
2015-12-10  4:18   ` D Gowers
2015-12-10  4:29     ` Nikolay Aleksandrovich Pavlov (ZyX)
2015-12-10  5:00       ` D Gowers
2015-12-10  9:37         ` Peter Stephenson
2015-12-10 17:47           ` Nikolay Aleksandrovich Pavlov (ZyX)

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).