summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 5f20af1..605951c 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.100 2008/08/21 23:19:49 hobbs Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.101 2008/08/21 23:42:13 hobbs Exp $
*/
#include "tclInt.h"
@@ -3275,23 +3275,34 @@ TclReToGlob(
Tcl_DStringInit(dsPtr);
/*
- * "***=xxx" == "*xxx*"
+ * Write to the ds directly without the function overhead.
+ * An equivalent glob pattern can be no more than reStrLen+2 in size.
*/
- if ((reStrLen >= 4) && (memcmp("***=", reStr, 4) == 0)) {
- Tcl_DStringAppend(dsPtr, "*", 1);
- Tcl_DStringAppend(dsPtr, reStr + 4, reStrLen - 4);
- Tcl_DStringAppend(dsPtr, "*", 1);
- return TCL_OK;
- }
+ Tcl_DStringSetLength(dsPtr, reStrLen + 2);
+ dsStr = dsStrStart = Tcl_DStringValue(dsPtr);
/*
- * Write to the ds directly without the function overhead.
- * An equivalent glob pattern can be no more than reStrLen+2 in size.
+ * "***=xxx" == "*xxx*", watch for glob-sensitive chars.
*/
- Tcl_DStringSetLength(dsPtr, reStrLen + 2);
- dsStrStart = Tcl_DStringValue(dsPtr);
+ if ((reStrLen >= 4) && (memcmp("***=", reStr, 4) == 0)) {
+ *dsStr++ = '*';
+ for (p = reStr + 4; p < strEnd; p++) {
+ switch (*p) {
+ case '\\': case '*': case '[': case ']': case '?':
+ /* Only add \ where necessary for glob */
+ *dsStr++ = '\\';
+ /* fall through */
+ default:
+ *dsStr++ = *p;
+ break;
+ }
+ }
+ *dsStr++ = '*';
+ Tcl_DStringSetLength(dsPtr, dsStr - dsStrStart);
+ return TCL_OK;
+ }
/*
* Check for anchored REs (ie ^foo$), so we can use string equal if
@@ -3306,7 +3317,7 @@ TclReToGlob(
p = reStr;
anchorRight = 0;
lastIsStar = 0;
- dsStr = dsStrStart;
+
if (*p == '^') {
anchorLeft = 1;
p++;