PATCH: fix anchored pattern with --disable-multibyte

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
Just copied this code over from the multibyte branch.
---
 Src/glob.c             | 14 ++++++++++++--
 Test/D04parameter.ztst | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Src/glob.c b/Src/glob.c
index e9967cad1a..5c6288060a 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -3350,13 +3350,23 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr,
 	    /* Largest possible match at tail of string:       *
 	     * move forward along string until we get a match. *
 	     * Again there's no optimisation.                  */
-	    for (ioff = 0, t = s, umlen = uml; t <= send;
-		 ioff++, t++, umlen--) {
+	    for (ioff = 0, t = s, umlen = uml; t <= send; ioff++) {
 		set_pat_start(p, t-s);
 		if (pattrylen(p, t, send - t, umlen, &patstralloc, ioff)) {
 		    *sp = get_match_ret(&imd, t-s, uml);
 		    return 1;
 		}
+		if (fl & SUB_START)
+		    break;
+		if (t == send)
+		    break;
+		t++;
+		umlen--;
+	    }
+	    if (!(fl & SUB_START) && pattrylen(p, send, 0, 0,
+			                       &patstralloc, ioff)) {
+		*sp = get_match_ret(&imd, uml, uml);
+		return 1;
 	    }
 	    break;
 
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 218bca739b..6a039d4830 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2460,6 +2460,27 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
 >different
 >string
 
+  foo="abcdef"
+  print 1${foo/#abc/REPLACED}
+  print 2${foo/%abc/REPLACED}
+  print 3${foo/#%abc/REPLACED}
+  print 4${foo/#def/REPLACED}
+  print 5${foo/%def/REPLACED}
+  print 6${foo/#%def/REPLACED}
+  print 7${foo/#bc/REPLACED}
+  print 8${foo/%bc/REPLACED}
+  print 9${foo/#%bc/REPLACED}
+0:Respect anchors
+>1REPLACEDdef
+>2abcdef
+>3abcdef
+>4abcdef
+>5abcREPLACED
+>6abcdef
+>7abcdef
+>8abcdef
+>9abcdef
+
   my_width=6
   my_index=1
   my_options=Option1
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.