about summary refs log tree commit diff
path: root/Src/pattern.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-09-29 19:06:43 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-09-29 19:47:21 +0100
commitd07783628e935daab518509db123141ceb535a28 (patch)
tree3eab2a8ff3ce8630b0de3e16fef86ed3e4c0e6c1 /Src/pattern.c
parentf9d7651c2554bb5db0373f63185ff358f795ab3c (diff)
downloadzsh-d07783628e935daab518509db123141ceb535a28.tar.gz
zsh-d07783628e935daab518509db123141ceb535a28.tar.xz
zsh-d07783628e935daab518509db123141ceb535a28.zip
36700: unmetafy early for parameter match
Diffstat (limited to 'Src/pattern.c')
-rw-r--r--Src/pattern.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/Src/pattern.c b/Src/pattern.c
index 03ba37d92..8de372c9e 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -2204,7 +2204,10 @@ pattrylen(Patprog prog, char *string, int len, int unmetalen,
  * the pattern module) at which we are trying to match.
  * This is added in to the positions recorded in patbeginp and patendp
  * when we are looking for substrings.  Currently this only happens
- * in the parameter substitution code.
+ * in the parameter substitution code.  It refers to a real character
+ * offset, i.e. is already in the form ready for presentation to the
+ * general public --- this is necessary as we don't have the
+ * information to convert it down here.
  *
  * Note this is a character offset, i.e. a single possibly metafied and
  * possibly multibyte character counts as 1.
@@ -2292,7 +2295,8 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
 	     */
 	    if (!patstralloc->progstrunmeta)
 	    {
-		patstralloc->progstrunmeta = dupstring(progstr);
+		patstralloc->progstrunmeta =
+		    dupstrpfx(progstr, (int)prog->patmlen);
 		unmetafy(patstralloc->progstrunmeta,
 			 &patstralloc->progstrunmetalen);
 	    }
@@ -2346,7 +2350,7 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
 		 * In the orignal structure, but it might be unmetafied
 		 * for use with an unmetafied test string.
 		 */
-		patinlen = (int)prog->patmlen;
+		patinlen = pstrlen;
 		/* if matching files, must update globbing flags */
 		patglobflags = prog->globend;
 
@@ -2360,7 +2364,7 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
 			 * Unmetafied: pstrlen contains unmetafied
 			 * length in bytes.
 			 */
-			str = metafy(patinstart, pstrlen, META_ALLOC);
+			str = metafy(patinstart, pstrlen, META_DUP);
 			mlen = CHARSUB(patinstart, patinstart + pstrlen);
 		    } else {
 			str = ztrduppfx(patinstart, patinlen);
@@ -2454,8 +2458,8 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
 	    /*
 	     * Optimization: if we didn't find any Meta characters
 	     * to begin with, we don't need to look for them now.
-	     * Only do this if we did the unmetfication internally,
-	     * since otherwise it's too hard to work out.
+	     *
+	     * For patstralloc pased in, we want the unmetafied length.
 	     */
 	    if (patstralloc == &patstralloc_struct &&
 		patstralloc->unmetalen != origlen) {
@@ -2588,7 +2592,9 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
 
 /*
  * Return length of previous succesful match.  This is
- * in metafied bytes, i.e. includes a count of Meta characters.
+ * in metafied bytes, i.e. includes a count of Meta characters,
+ * unless the match was done on an unmetafied string using
+ * a patstralloc stuct, in which case it, too is unmetafed.
  * Unusual and futile attempt at modular encapsulation.
  */