Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Quoting problem and crashes with ${(#)var}



Bart Schaefer wrote:
> With zsh -f from the latest CVS as of 2007-02-10 10:28 AM PST:
> 
> torch% for x in {1..255}; echo -n ${(#)x}; echo ''

I think this is it, but shout if you can see any problems left...
This was always a bit broken, since the character was never metafied
properly, but UTF-8 gave exciting new was for bogus tokens to get into
the input.  I also forgot the MULTIBYTE_SUPPORT test.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.74
diff -u -r1.74 subst.c
--- Src/subst.c	2 Feb 2007 21:42:15 -0000	1.74
+++ Src/subst.c	10 Feb 2007 22:07:29 -0000
@@ -1193,21 +1193,25 @@
 substevalchar(char *ptr)
 {
     zlong ires = mathevali(ptr);
+    int len;
 
     if (errflag)
 	return NULL;
+#ifdef MULTIBYTE_SUPPORT
     if (isset(MULTIBYTE) && ires > 127) {
 	char buf[10];
-	int dummy;
 
 	/* inefficient: should separate out \U handling from getkeystring */
 	sprintf(buf, "\\U%.8x", (unsigned int)ires);
-	return getkeystring(buf, &dummy, GETKEYS_BINDKEY, NULL);
-    } else {
+	ptr = getkeystring(buf, &len, GETKEYS_BINDKEY, NULL);
+    } else
+#endif
+    {
 	ptr = zhalloc(2);
+	len = 1;
 	sprintf(ptr, "%c", (int)ires);
-	return ptr;
     }
+    return metafy(ptr, len, META_USEHEAP);
 }
 
 /* parameter substitution */
Index: Test/D07multibyte.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v
retrieving revision 1.14
diff -u -r1.14 D07multibyte.ztst
--- Test/D07multibyte.ztst	22 Jan 2007 14:35:14 -0000	1.14
+++ Test/D07multibyte.ztst	10 Feb 2007 22:07:29 -0000
@@ -326,3 +326,35 @@
 0:Multibyte characters in print sorting
 >HAH HEH HÉH HÈH HUH
 >HAH HEH HUH HÈH HÉH
+
+# These are control characters in Unicode, so don't show up.
+# We just want to check they're not being treated as tokens.
+  for x in {128..150}; do
+     print ${(#)x}
+  done | while read line; do
+    print ${#line} $(( #line ))
+  done
+0:evaluated character number with multibyte characters
+>1 128
+>1 129
+>1 130
+>1 131
+>1 132
+>1 133
+>1 134
+>1 135
+>1 136
+>1 137
+>1 138
+>1 139
+>1 140
+>1 141
+>1 142
+>1 143
+>1 144
+>1 145
+>1 146
+>1 147
+>1 148
+>1 149
+>1 150

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author