From f137e44fa1a2dd7603fba62d1b44c103379e2781 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 7 Apr 2006 14:05:26 +0000 Subject: * generic/tclPathObj.c: Yet another revised fix for the [Bug 1379287] * tests/fileSystem.test: family of path normalization bugs. --- ChangeLog | 5 +++++ generic/tclPathObj.c | 17 ++++++++++++----- tests/fileSystem.test | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d4c114..2bcfcca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-04-07 Don Porter + + * generic/tclPathObj.c: Yet another revised fix for the [Bug 1379287] + * tests/fileSystem.test: family of path normalization bugs. + 2006-04-06 Jeff Hobbs * generic/tclRegexp.c (FinalizeRegexp): full reset data to diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c index 161d7de..ba8d155 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.54 2006/04/06 16:43:03 dgp Exp $ + * RCS: @(#) $Id: tclPathObj.c,v 1.55 2006/04/07 14:05:29 dgp Exp $ */ #include "tclInt.h" @@ -213,13 +213,17 @@ TclFSNormalizeAbsolutePath( /* * Need to skip '.' in the path. */ + int curLen; if (retVal == NULL) { CONST char *path = TclGetString(pathPtr); - retVal = Tcl_NewStringObj(path, dirSep - path - + (dirSep == path)); + retVal = Tcl_NewStringObj(path, dirSep - path); Tcl_IncrRefCount(retVal); } + Tcl_GetStringFromObj(retVal, &curLen); + if (curLen == 0) { + Tcl_AppendToObj(retVal, dirSep, 1); + } dirSep += 2; oldDirSep = dirSep; if (dirSep[0] != 0 && dirSep[1] == '.') { @@ -238,10 +242,13 @@ TclFSNormalizeAbsolutePath( if (retVal == NULL) { CONST char *path = TclGetString(pathPtr); - retVal = Tcl_NewStringObj(path, dirSep - path - + (dirSep == path)); + retVal = Tcl_NewStringObj(path, dirSep - path); Tcl_IncrRefCount(retVal); } + Tcl_GetStringFromObj(retVal, &curLen); + if (curLen == 0) { + Tcl_AppendToObj(retVal, dirSep, 1); + } if (!first || (tclPlatform == TCL_PLATFORM_UNIX)) { link = Tcl_FSLink(retVal, NULL, 0); if (link != NULL) { diff --git a/tests/fileSystem.test b/tests/fileSystem.test index 39e02c4..87e5e26 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -473,6 +473,26 @@ test filesystem-1.50 {file normalisation .. beyond root (Bug 1379287)} { set res "ok" } } {ok} +test filesystem-1.51 {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.51.1 {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*]] { -- cgit v0.12