zsh-workers
 help / color / mirror / code / Atom feed
From: "Matthias B." <msbREMOVE-THIS@winterdrache.de>
To: zsh-workers@sunsite.dk
Subject: BUG: tied parameters with NUL-separator
Date: Mon, 13 Sep 2004 20:25:17 +0200	[thread overview]
Message-ID: <20040913202517.79418def@buddha.localdomain.de> (raw)

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.


             reply	other threads:[~2004-09-13 18:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-13 18:25 Matthias B. [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040913202517.79418def@buddha.localdomain.de \
    --to=msbremove-this@winterdrache.de \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).