From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18261 invoked from network); 23 Oct 2004 16:33:50 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 23 Oct 2004 16:33:50 -0000 Received: (qmail 12042 invoked from network); 22 Oct 2004 15:33:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 22 Oct 2004 15:33:45 -0000 Received: (qmail 16520 invoked by alias); 22 Oct 2004 15:33:32 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20513 Received: (qmail 16506 invoked from network); 22 Oct 2004 15:33:30 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 22 Oct 2004 15:33:30 -0000 Received: (qmail 11521 invoked from network); 22 Oct 2004 15:32:31 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 22 Oct 2004 15:32:30 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i9MFWTv13771 for ; Fri, 22 Oct 2004 15:32:29 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 22 Oct 2004 16:31:24 +0100 Received: from news01.csr.com ([192.168.143.38]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 22 Oct 2004 16:35:21 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id i9MFWNX2004966 for ; Fri, 22 Oct 2004 16:32:23 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id i9MFWMF8004963 for ; Fri, 22 Oct 2004 16:32:23 +0100 Message-Id: <200410221532.i9MFWMF8004963@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: Bug in [[ "" == "" ]] expressions? In-reply-to: References: Date: Fri, 22 Oct 2004 16:32:22 +0100 From: Peter Stephenson X-OriginalArrivalTime: 22 Oct 2004 15:35:21.0281 (UTC) FILETIME=[BDB22310:01C4B84C] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Felix Rosencrantz wrote: > It seems like zsh on 10-8 works like I'm use to, but a change since > then has changed the behavior. Not sure if Peter intended this. > > Comparing an empty or unset string against an empty pattern returns > false. Here's the code: > zsh -f > % a="" > % b="abc" > % [[ "$a" == "" ]] ; echo $status > 1 > % [[ "$b" == "abc" ]] ; echo $status > 0 > % [[ "$c" == "" ]] ; echo $status > 1 This is because of a feature I've never understood whereby zero-length metafied strings are turned into a Nularg token plus the usual NULL. I didn't handle this properly. This also makes sure that a zero-length string in a pattern is optimised to be recognised as a pure string, for which memcmp rather than the full pattern matcher can be used. (Hmm, I hope memcmp'ing zero bytes is portable.) Index: Src/pattern.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v retrieving revision 1.22 diff -u -r1.22 pattern.c --- Src/pattern.c 18 Oct 2004 11:56:17 -0000 1.22 +++ Src/pattern.c 22 Oct 2004 15:28:36 -0000 @@ -399,7 +399,7 @@ patendstr++; patendseglen--; patendstrlen--; - remnulargs(exp); + remnulargs(patparse); patglobflags = 0; } /* @@ -419,10 +419,20 @@ || (!(patglobflags & ~GF_IGNCASE) && (patflags & PAT_FILE)) #endif ) + { + /* + * Waah! I wish I understood this. + * Empty metafied strings have an initial Nularg. + * This never corresponds to a real character in + * a glob pattern or string, so skip it. + */ + if (*exp == Nularg) + exp++; for (strp = exp; *strp && (!(patflags & PAT_FILE) || *strp != '/') && !itok(*strp); strp++) ; + } if (!strp || (*strp && *strp != '/')) { /* No, do normal compilation. */ strp = NULL; @@ -1010,6 +1020,9 @@ /* Get length of string without metafication. */ nmeta = 0; + /* inherited from domatch, but why, exactly? */ + if (*str0 == Nularg) + str0++; for (ptr = str0; ptr < patparse; ptr++) { if (*ptr == Meta) { nmeta++; Index: Test/D02glob.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v retrieving revision 1.6 diff -u -r1.6 D02glob.ztst --- Test/D02glob.ztst 18 Oct 2004 11:56:18 -0000 1.6 +++ Test/D02glob.ztst 22 Oct 2004 15:28:36 -0000 @@ -308,3 +308,7 @@ print glob.tmp/**/*~*/dir3(/*|(#e))(/) 0:Exclusions with complicated path specifications >glob.tmp/dir1 glob.tmp/dir2 glob.tmp/dir4 + + [[ "" = "" ]] && echo OK +0:Empty strings +>OK -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************