zsh-workers
 help / color / mirror / code / Atom feed
* BUG: tied parameters with NUL-separator
@ 2004-09-13 18:25 Matthias B.
  2004-09-16 20:15 ` PATCH: incorrect tied param splitting/joining when imeta(separator) is true Matthias B.
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias B. @ 2004-09-13 18:25 UTC (permalink / raw)
  To: zsh-workers

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.


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

end of thread, other threads:[~2004-09-17  9:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13 18:25 BUG: tied parameters with NUL-separator Matthias B.
2004-09-16 20:15 ` PATCH: incorrect tied param splitting/joining when imeta(separator) is true Matthias B.
2004-09-17  9:28   ` Peter Stephenson

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).