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

PATCH: Re: Quoting and ${(e)param} (was Re: destructive list-expand)



Bart Schaefer wrote:

> ...
> 
> } So the easiest solution would be to just make paramsubst() always
> } tokenize the pattern strings, not only if it knows that the parameter
> } expansion is in quotes. I was fearing that this might result in some
> } quoting problems (having to double backslashes or some such), but it
> } seems to work, including handling of parameter expansions inside
> } patterns.
> 
> Yes, it's pretty obvious that it should work:  parse_subst_str() does
> an untokenize() before it lexes the string, so it won't matter if the
> string is or is not already tokenized.  All that your patch is doing is
> removing an optimization.

Yes, I was hoping to be able somehow to keep that optimization. Sigh.

> Consequently I think it would be OK to include it (possibly with the #if
> replaced by an explanatory comment).  It'll slow down expansion of un-
> quoted parameters slightly in the name of correctness, a tradeoff I made
> several times in my subscript-parsing changes.

Ok, then, here's the final version of the patch.

Bye
  Sven

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.17
diff -u -r1.17 subst.c
--- Src/subst.c	2001/04/28 17:38:01	1.17
+++ Src/subst.c	2001/05/18 12:36:31
@@ -720,9 +720,13 @@
 
     if (!(err ? parsestr(s) : parsestrnoerr(s))) {
 	if (!single) {
+            int qt = 0;
+
 	    for (; *s; s++)
-		if (*s == Qstring)
+		if (!qt && *s == Qstring)
 		    *s = String;
+                else if (*s == Dnull)
+                    qt = !qt;
 	}
 	return 0;
     }
@@ -1483,7 +1487,14 @@
 	case '#':
 	case Pound:
 	case '/':
-	    if (qt) {
+            /* This once was executed only `if (qt) ...'. But with that
+             * patterns in a expansion resulting from a ${(e)...} aren't
+             * tokenized even though this function thinks they are (it thinks
+             * they are because subst_parse_string() turns Qstring tokens
+             * into String tokens and for unquoted parameter expansions the
+             * lexer normally does tokenize patterns inside parameter
+             * expansions). */
+            {
 		int one = noerrs, oef = errflag, haserr;
 
 		if (!quoteerr)

-- 
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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