summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--generic/tclPathObj.c24
-rw-r--r--tests/fileSystem.test40
3 files changed, 58 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 0966c2f..95eec59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
* changes: Updates for another RC.
+ * generic/tclPathObj.c: More fixes for path normalization when /../
+ * tests/fileSystem.test: tries to go beyond root.[Bug 1379287]
+
* generic/tclExecute.c: Revised INST_MOD implementation to do
calculations in native types as much as possible, moving to mp_ints
only when necessary.
diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c
index a40d448..f546d11 100644
--- a/generic/tclPathObj.c
+++ b/generic/tclPathObj.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPathObj.c,v 1.52 2006/03/04 02:33:36 dgp Exp $
+ * RCS: @(#) $Id: tclPathObj.c,v 1.53 2006/03/29 22:19:11 dgp Exp $
*/
#include "tclInt.h"
@@ -158,14 +158,14 @@ TclFSNormalizeAbsolutePath(
* of normalization. */
{
ClientData clientData = NULL;
- CONST char *dirSep, *oldDirSep, *pathString;
+ CONST char *dirSep, *oldDirSep, *path;
int first = 1; /* Set to zero once we've passed the first
* directory separator - we can't use '..' to
* remove the volume in a path. */
int rootOffset = -1;
int unc = 0;
Tcl_Obj *retVal = NULL;
- pathString = dirSep = TclGetString(pathPtr);
+ path = dirSep = TclGetString(pathPtr);
if (tclPlatform == TCL_PLATFORM_WINDOWS) {
if (dirSep[0] != 0 && dirSep[1] == ':' &&
@@ -196,7 +196,7 @@ TclFSNormalizeAbsolutePath(
while (*dirSep != 0) {
if ((rootOffset == -1) && IsSeparatorOrNull(dirSep[0])) {
- rootOffset = dirSep - pathString;
+ rootOffset = dirSep - path;
}
oldDirSep = dirSep;
if (!first) {
@@ -204,7 +204,7 @@ TclFSNormalizeAbsolutePath(
}
dirSep += FindSplitPos(dirSep, '/');
if (rootOffset == -1) {
- rootOffset = dirSep - pathString;
+ rootOffset = dirSep - path;
}
if (dirSep[0] == 0 || dirSep[1] == 0) {
if (retVal != NULL) {
@@ -224,8 +224,8 @@ TclFSNormalizeAbsolutePath(
*/
if (retVal == NULL) {
- CONST char *path = TclGetString(pathPtr);
- retVal = Tcl_NewStringObj(path, dirSep - path);
+ retVal = Tcl_NewStringObj(path, dirSep - path
+ + (rootOffset == dirSep - path));
Tcl_IncrRefCount(retVal);
}
dirSep += 2;
@@ -245,8 +245,8 @@ TclFSNormalizeAbsolutePath(
*/
if (retVal == NULL) {
- CONST char *path = TclGetString(pathPtr);
- retVal = Tcl_NewStringObj(path, dirSep - path);
+ retVal = Tcl_NewStringObj(path, dirSep - path
+ + (rootOffset == dirSep - path));
Tcl_IncrRefCount(retVal);
}
if (!first || (tclPlatform == TCL_PLATFORM_UNIX)) {
@@ -332,6 +332,12 @@ TclFSNormalizeAbsolutePath(
Tcl_SetObjLength(retVal, rootOffset+1);
}
}
+ } else {
+ if ((dirSep[3] != 0) || unc) {
+ Tcl_SetObjLength(retVal, rootOffset);
+ } else {
+ Tcl_SetObjLength(retVal, rootOffset+1);
+ }
}
dirSep += 3;
oldDirSep = dirSep;
diff --git a/tests/fileSystem.test b/tests/fileSystem.test
index 06ab643..39e02c4 100644
--- a/tests/fileSystem.test
+++ b/tests/fileSystem.test
@@ -433,6 +433,46 @@ test filesystem-1.46 {file normalisation .. beyond root (Bug 1379287)} {
set res "ok"
}
} {ok}
+test filesystem-1.47 {file normalisation .. beyond root (Bug 1379287)} {
+ set a [file norm /..]
+ set b [file norm /]
+
+ if {![string equal $a $b]} {
+ set res "Paths should be equal: $a , $b"
+ } else {
+ set res "ok"
+ }
+} {ok}
+test filesystem-1.48 {file normalisation .. beyond root (Bug 1379287)} {
+ set a [file norm /../]
+ set b [file norm /]
+
+ if {![string equal $a $b]} {
+ set res "Paths should be equal: $a , $b"
+ } else {
+ set res "ok"
+ }
+} {ok}
+test filesystem-1.49 {file normalisation .. beyond root (Bug 1379287)} {
+ set a [file norm /.]
+ set b [file norm /]
+
+ if {![string equal $a $b]} {
+ set res "Paths should be equal: $a , $b"
+ } else {
+ set res "ok"
+ }
+} {ok}
+test filesystem-1.50 {file normalisation .. beyond root (Bug 1379287)} {
+ set a [file norm /./]
+ set b [file norm /]
+
+ if {![string equal $a $b]} {
+ set res "Paths should be equal: $a , $b"
+ } else {
+ set res "ok"
+ }
+} {ok}
test filesystem-2.0 {new native path} {unix} {
foreach f [lsort [glob -nocomplain /usr/bin/c*]] {