summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2008-08-21 23:42:13 (GMT)
committerhobbs <hobbs>2008-08-21 23:42:13 (GMT)
commitedfda9078ba74cdc4c6038b014e610f7b6efcc96 (patch)
tree0c69378f1b317342afcb90c05331a8a6cb468951 /generic/tclUtil.c
parentb960e085fa96bdac779fd6c41f343d7bf4d6e4e6 (diff)
downloadtcl-edfda9078ba74cdc4c6038b014e610f7b6efcc96.zip
tcl-edfda9078ba74cdc4c6038b014e610f7b6efcc96.tar.gz
tcl-edfda9078ba74cdc4c6038b014e610f7b6efcc96.tar.bz2
really fix translation to escape glob-sensitive chars
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++;