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

Re: _call_program (and possibly other hooks) or opt_args quoting prob lem.



Borsenkow Andrej wrote:

> ...
> 
> What happens currently is, zsh removes quoting when it stores values in
> opt_args array but it does not expand it. After this is done there is no
> way to recover original string as entered by user. So in cases when you
> may want it (see above example _foo) you have no means to get real
> value.

It's the code affected by the patch below (which I'm not going to
commit right now, only if I get replies). We need the de-quoting
because options may be partly quoted (Bart once send a message about
this and as a consequence I added the de-quoting code).

I'm not sure if we should commit this patch, because, as was already
pointed out, ${(e)...} on a string as it is reported now should give
one the needed expansion. With the patch that would become ${(Qe)...}.

Any opinions?


Bye
  Sven

P.S.: The patch may be offset, never mind.

diff -ur -r ../oz/Src/Zle/computil.c ./Src/Zle/computil.c
--- ../oz/Src/Zle/computil.c	Sat May 18 20:31:04 2002
+++ ./Src/Zle/computil.c	Sat May 18 23:28:25 2002
@@ -1693,6 +1695,33 @@
     zfree(s->oargs, s->d->nopts * sizeof(LinkList));
 }
 
+/* Return a copy of an option's argument, ignoring possible quoting
+ * in the option name. */
+
+static char *
+ca_opt_arg(Caopt opt, char *line)
+{
+    char *o = opt->name;
+
+    while (1) {
+        if (*o == '\\')
+            o++;
+        if (*line == '\\' || *line == '\'' || *line == '"')
+            line++;
+        if (!*o || *o != *line)
+            break;
+        o++;
+        line++;
+    }
+    if (*line && (opt->type == CAO_EQUAL || opt->type == CAO_OEQUAL)) {
+        if (*line == '\\')
+            line++;
+        if (*line == '=')
+            line++;
+    }
+    return ztrdup(line);
+}
+
 /* Parse a command line. */
 
 static int
@@ -1701,7 +1730,7 @@
     Caarg adef, ddef;
     Caopt ptr, wasopt = NULL, dopt;
     struct castate state;
-    char *line, *pe, **argxor = NULL;
+    char *line, *oline, *pe, **argxor = NULL;
     int cur, doff, argend, arglast, ne;
     Patprog endpat = NULL, napat = NULL;
     LinkList sopts = NULL;
@@ -1767,6 +1796,7 @@
 	doff = state.singles = arglast = 0;
 
         /* remove quotes */
+        oline = line;
         line = dupstring(line);
         ne = noerrs;
         noerrs = 2;
@@ -1786,7 +1816,7 @@
 	if (state.def) {
 	    state.arg = 0;
 	    if (state.curopt)
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(line));
+		zaddlinknode(state.oargs[state.curopt->num], ztrdup(oline));
 
 	    if ((state.opt = (state.def->type == CAA_OPT)) && state.def->opt)
 		state.oopt++;
@@ -1868,7 +1898,8 @@
 		    state.def->type != CAA_RREST)
 		    state.def = state.def->next;
 
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(pe));
+		zaddlinknode(state.oargs[state.curopt->num],
+                             ca_opt_arg(state.curopt, oline));
 	    }
 	    if (state.def)
 		state.opt = 0;
@@ -1921,7 +1952,8 @@
 		    state.def->type != CAA_RREST)
 		    state.def = state.def->next;
 
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(pe));
+		zaddlinknode(state.oargs[state.curopt->num],
+                             ca_opt_arg(state.curopt, line));
 	    }
 	    if (state.def)
 		state.opt = 0;

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



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