about summary refs log tree commit diff
path: root/Src/params.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-05-21 09:30:24 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-05-21 09:30:24 +0000
commitfaf05be3d2adc99212af74e2507a66de1161a52a (patch)
tree7a0ac19d76eff3142484c02a83388a5e52848535 /Src/params.c
parent86ff81f82d97b0118eddb729a2d4956fcbdd7c7a (diff)
downloadzsh-faf05be3d2adc99212af74e2507a66de1161a52a.tar.gz
zsh-faf05be3d2adc99212af74e2507a66de1161a52a.tar.xz
zsh-faf05be3d2adc99212af74e2507a66de1161a52a.zip
23440: Make $param[(R)value] substitute the empty string on failure
Diffstat (limited to 'Src/params.c')
-rw-r--r--Src/params.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Src/params.c b/Src/params.c
index ed8b4a412..14ff4f6ca 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1276,6 +1276,19 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 			if (pprog && pattry(pprog, *p) && !--num)
 			    return r;
 		    }
+		    /*
+		     * Failed to match.
+		     * If we're returning an index, return 0 to show
+		     * we've gone off the start.  Unfortunately this
+		     * is ambiguous with KSH_ARRAYS set, but we're
+		     * stuck with that now.
+		     *
+		     * If the index is to be turned into an element,
+		     * return an index that does not point to a valid
+		     * element (since 0 is treated the same as 1).
+		     */
+		    if (!ind)
+			r = len + 1;
 		} else
 		    for (r = 1 + beg, p = ta + beg; *p; r++, p++)
 			if (pprog && pattry(pprog, *p) && !--num)
@@ -1495,7 +1508,13 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 		    }
 		}
 	    }
-	    return down ? 0 : slen + 1;
+	    /*
+	     * Failed to match.
+	     * If the argument selects an element rather than
+	     * its index, ensure the element is empty.
+	     * See comments on the array case above.
+	     */
+	    return (down && ind) ? 0 : slen + 1;
 	}
     }
     return r;