diff options
author | hobbs <hobbs> | 2008-02-26 20:18:13 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2008-02-26 20:18:13 (GMT) |
commit | a46d1b4c18dd41db8e81fd46a75453453d8e3da9 (patch) | |
tree | 830b495ac344ea81098ebb316aa4d14fe1445620 /generic/tclUtil.c | |
parent | 4af7381c98a78ec974b2febf9fc9543d2fa04e8f (diff) | |
download | tcl-a46d1b4c18dd41db8e81fd46a75453453d8e3da9.zip tcl-a46d1b4c18dd41db8e81fd46a75453453d8e3da9.tar.gz tcl-a46d1b4c18dd41db8e81fd46a75453453d8e3da9.tar.bz2 |
* generic/tclUtil.c (TclReToGlob): fix the handling of the last
* tests/regexpComp.test: star possibly being escaped in
determining right anchor. [Bug 1902436]
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r-- | generic/tclUtil.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index ea3eec1..07fbc87 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtil.c,v 1.96 2007/12/13 15:23:20 dgp Exp $ + * RCS: @(#) $Id: tclUtil.c,v 1.97 2008/02/26 20:18:14 hobbs Exp $ */ #include "tclInt.h" @@ -3270,7 +3270,7 @@ TclReToGlob( Tcl_DString *dsPtr, int *exactPtr) { - int anchorLeft, anchorRight; + int anchorLeft, anchorRight, lastIsStar; char *dsStr, *dsStrStart, *msg; const char *p, *strEnd; @@ -3300,11 +3300,16 @@ TclReToGlob( /* * Check for anchored REs (ie ^foo$), so we can use string equal if * possible. Do not alter the start of str so we can free it correctly. + * + * Keep track of the last char being an unescaped star to prevent + * multiple instances. Simpler than checking that the last star + * may be escaped. */ msg = NULL; p = reStr; anchorRight = 0; + lastIsStar = 0; dsStr = dsStrStart; if (*p == '^') { anchorLeft = 1; @@ -3312,6 +3317,7 @@ TclReToGlob( } else { anchorLeft = 0; *dsStr++ = '*'; + lastIsStar = 1; } for ( ; p < strEnd; p++) { @@ -3364,14 +3370,16 @@ TclReToGlob( if (p+1 < strEnd) { if (p[1] == '*') { p++; - if ((dsStr == dsStrStart) || (dsStr[-1] != '*')) { + if (!lastIsStar) { *dsStr++ = '*'; + lastIsStar = 1; } continue; } else if (p[1] == '+') { p++; *dsStr++ = '?'; *dsStr++ = '*'; + lastIsStar = 1; continue; } } @@ -3393,8 +3401,9 @@ TclReToGlob( *dsStr++ = *p; break; } + lastIsStar = 0; } - if (!anchorRight && ((dsStr == dsStrStart) || (dsStr[-1] != '*'))) { + if (!anchorRight && !lastIsStar) { *dsStr++ = '*'; } Tcl_DStringSetLength(dsPtr, dsStr - dsStrStart); |