From a46d1b4c18dd41db8e81fd46a75453453d8e3da9 Mon Sep 17 00:00:00 2001 From: hobbs Date: Tue, 26 Feb 2008 20:18:13 +0000 Subject: * generic/tclUtil.c (TclReToGlob): fix the handling of the last * tests/regexpComp.test: star possibly being escaped in determining right anchor. [Bug 1902436] --- ChangeLog | 6 ++++++ generic/tclUtil.c | 17 +++++++++++++---- tests/regexpComp.test | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e584f94..d2196c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-26 Jeff Hobbs + + * generic/tclUtil.c (TclReToGlob): fix the handling of the last + * tests/regexpComp.test: star possibly being escaped in + determining right anchor. [Bug 1902436] + 2008-02-26 Pat Thoyts * library/http/pkgIndex.tcl: Set version 2.5.5 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); diff --git a/tests/regexpComp.test b/tests/regexpComp.test index 0278033..c7a5980 100644 --- a/tests/regexpComp.test +++ b/tests/regexpComp.test @@ -909,6 +909,22 @@ test regexpComp-24.9 {regexp command compiling tests} { list [catch {regexp -- $re dogfod} msg] $msg } } {1 {couldn't compile regular expression pattern: parentheses () not balanced}} +test regexpComp-24.10 {regexp command compiling tests} { + # Bug 1902436 - last * escaped + evalInProc { + set text {this is *bold* !} + set re {\*bold\*} + regexp -- $re $text + } +} 1 +test regexpComp-24.11 {regexp command compiling tests} { + # Bug 1902436 - last * escaped + evalInProc { + set text {this is *bold* !} + set re {\*bold\*.*!} + regexp -- $re $text + } +} 1 # cleanup ::tcltest::cleanupTests -- cgit v0.12