From c8e70ab5cffaffacf6d0a4e81df4fbd685378bfd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 26 Oct 2004 17:20:21 +0000 Subject: 20522: must-match optimisation in parameter substitution broken --- ChangeLog | 5 +++++ Src/glob.c | 16 ++++++++++++++-- Test/D02glob.ztst | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6852687c..ddf0e1143 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-10-26 Peter Stephenson + + * 20522: Src/glob.c, Test/D02glob.ztst: must-match optimisation + was broken for pattern substitutions in parameters. + 2004-10-22 Wayne Davison * 20510: Borzenkov Andrey: Src/jobs.c: Fixed the arg to a call diff --git a/Src/glob.c b/Src/glob.c index 84ee8a751..5519e0e02 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -2206,8 +2206,20 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr) repllist = NULL; /* perform must-match test for complex closures */ - if (p->mustoff && !strstr((char *)s, (char *)p + p->mustoff)) - matched = 0; + if (p->mustoff) + { + /* + * Yuk. Probably we should rewrite this whole function to + * use an unmetafied test string. + * + * Use META_HEAPDUP because we need a terminating NULL. + */ + char *muststr = metafy((char *)p + p->mustoff, + p->patmlen, META_HEAPDUP); + + if (!strstr(s, muststr)) + matched = 0; + } /* in case we used the prog before... */ p->flags &= ~(PAT_NOTSTART|PAT_NOTEND); diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst index c7976225d..f35e5eb75 100644 --- a/Test/D02glob.ztst +++ b/Test/D02glob.ztst @@ -312,3 +312,8 @@ [[ "" = "" ]] && echo OK 0:Empty strings >OK + + foo="this string has a : colon in it" + print ${foo%% #:*} +0:Must-match arguments in complex patterns +>this string has a -- cgit v1.2.3-70-g09d2