Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

BUG: tied parameters with NUL-separator



The following works as expected in zsh 4.2.1
(NOTE: hexd is a hexdump script that displays 
offset: hex   correspondingchars)

pmt> unset foo
pmt> unset bar
pmt> sep=:
pmt> foo='a:b:c'
pmt> typeset -T foo bar "$sep"
pmt> echo -n "${bar[1]}" | hexd
00000: 61                 a
pmt> echo -n "${bar[2]}" | hexd
00000: 62                 b
pmt> echo -n "${bar[3]}" | hexd
00000: 63                 c
pmt> bar[3]='1 2'
pmt> echo -n "${bar[3]}" | hexd
00000: 31 20 32               1 2
pmt> echo -n "$foo" | hexd
00000: 61 3a 62 3a 31 20 32           a:b:1 2


Now look what happens when I use NUL as separator

pmt> unset foo
pmt> unset bar
pmt> sep=$'\0'
pmt> foo=$'a\0b\0c'
pmt> typeset -T foo bar "$sep"
pmt> echo -n "${bar[1]}" | hexd
00000: 61                 a
pmt> echo -n "${bar[2]}" | hexd
00000: 20 62                 b
pmt> echo -n "${bar[3]}" | hexd
00000: 20 63                 c
pmt> bar[3]='1 2'
pmt> echo -n "${bar[3]}" | hexd
00000: 31 20 32               1 2
pmt> echo -n "$foo" | hexd
00000: 61 20 62 31 20             a b1 


So we have 2 bugs here:

1) When typeset -T splits foo it inserts a space in front of all elements
but the 1st one. This only happens when splitting apparently. Assigning to
an element directly does not insert a space.

2) Re-assembling the scalar doesn't work. The separators are not inserted
at all and the part after the space in the string '1 2' assigned to
element 3 gets lost somehow.


I know that I probably shouldn't complain. I'm actually quite impressed
that embedding NULs in strings works at all. Few C-programs have
binary-clean string-handling.
But it's such a useful feature and since it works almost perfectly already
I'm hopeful that this can be made to work fully. I'm really looking
forward to this, because I want to parse output from find into an array
and since pathnames can in theory contain every character but NUL, using
NUL as separator seems to be the only way to achieve this. 

Bug 1) is the important one for me as I'm only interested in splitting, so
a fix for that would be appreciated even if Bug 2) would take too much
effort to fix.

MSB

-- 
pragma est dogma.



Messages sorted by: Reverse Date, Date, Thread, Author