Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug in [[ "" == "" ]] expressions?
- X-seq: zsh-workers 20513
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Bug in [[ "" == "" ]] expressions?
- Date: Fri, 22 Oct 2004 16:32:22 +0100
- In-reply-to: <dc507f4a041022075810003f7@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <dc507f4a041022075810003f7@xxxxxxxxxxxxxx>
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 <pws@xxxxxxx> 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
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author