From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21490 invoked from network); 14 Feb 2007 16:06:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 Feb 2007 16:06:40 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 86295 invoked from network); 14 Feb 2007 16:06:33 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 Feb 2007 16:06:33 -0000 Received: (qmail 12752 invoked by alias); 14 Feb 2007 16:06:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23176 Received: (qmail 12742 invoked from network); 14 Feb 2007 16:06:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 14 Feb 2007 16:06:30 -0000 Received: (qmail 86062 invoked from network); 14 Feb 2007 16:06:30 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 14 Feb 2007 16:06:20 -0000 Received: from torch.brasslantern.com ([71.116.79.148]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JDG00ACKNAMPOT0@vms044.mailsrvcs.net> for zsh-workers@sunsite.dk; Wed, 14 Feb 2007 10:03:59 -0600 (CST) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id l1EG3li2026430 for ; Wed, 14 Feb 2007 08:03:49 -0800 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id l1EG3ld7026429 for zsh-workers@sunsite.dk; Wed, 14 Feb 2007 08:03:47 -0800 Date: Wed, 14 Feb 2007 08:03:47 -0800 From: Bart Schaefer Subject: Re: Quoting problem and crashes with ${(#)var} In-reply-to: <200702141016.l1EAGpKF016735@news01.csr.com> To: zsh-workers@sunsite.dk Message-id: <070214080347.ZM26428@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <200702132111.l1DLB5rA003849@pwslaptop.csr.com> <070213234815.ZM5424@torch.brasslantern.com> <200702141016.l1EAGpKF016735@news01.csr.com> Comments: In reply to Peter Stephenson "Re: Quoting problem and crashes with ${(#)var}" (Feb 14, 10:16am) On Feb 14, 10:16am, Peter Stephenson wrote: } Subject: Re: Quoting problem and crashes with ${(#)var} } } > } (However, the ZLE function insert-unicode-char correctly } > } shows it as control character, ^ followed by A with a grave accent.) } > } > That's what I expected ${(V)x} to do, but instead it displays it as a } > \u escape. } >... } > I'm asking for two things: } > } > (1) when "character not in range" we don't treat it as a fatal error } > and bail out of the whole surrounding loop; and On further thought, it ought to be possible to test whether a character is within range, so how about this: Extend the (X) flag to cover (#) as well as (Qqe). Then ${(X#):-129} throws an error when LANG=C and multibyte support is enabled, but ${(#):-129} does not. Code (but not yet doc) patch below (ignore the diff in 23173). } > (2) regardless of the locale, single-byte values should always be } > convertible to something "viewable", either \u00xy or \M-c. } } Passing the character through the appropriate version of nicechar() } ought to help. Unfortunately that doesn't seem to be enough: the (V) flag is already calling nicedupstring(). It looks like wcs_nicechar() only uses the carat-character format for control characters less than 0x80? ZLE must be doing its own printable conversion somewhere else. --- Src/subst.c 2007-02-14 07:59:29.000000000 -0800 +++ /tmp/subst.c 2007-02-14 07:59:29.000000000 -0800 @@ -1193,7 +1193,7 @@ substevalchar(char *ptr) { zlong ires = mathevali(ptr); - int len; + int len = 0; if (errflag) return NULL; @@ -1204,7 +1204,8 @@ /* inefficient: should separate out \U handling from getkeystring */ sprintf(buf, "\\U%.8x", (unsigned int)ires); ptr = getkeystring(buf, &len, GETKEYS_BINDKEY, NULL); - } else + } + if (len == 0) #endif { ptr = zhalloc(2); @@ -2658,6 +2659,10 @@ if (errflag) return NULL; if (evalchar) { + int one = noerrs, oef = errflag, haserr; + + if (!quoteerr) + noerrs = 1; /* * Evaluate the value numerically and output the result as * a character. @@ -2669,15 +2674,24 @@ for (avptr = aval, av2ptr = aval2; *avptr; avptr++, av2ptr++) { - if (!(*av2ptr = substevalchar(*avptr))) - return NULL; + /* When noerrs = 1, the only error is out-of-memory */ + if (!(*av2ptr = substevalchar(*avptr))) { + haserr = 1; + break; + } } *av2ptr = NULL; aval = aval2; } else { + /* When noerrs = 1, the only error is out-of-memory */ if (!(val = substevalchar(val))) - return NULL; + haserr = 1; } + noerrs = one; + if (!quoteerr) + errflag = oef; + if (haserr || errflag) + return NULL; } /* * This handles taking a length with ${#foo} and variations.