From 074f543ea2e37afc36c7f281e75575d211bde796 Mon Sep 17 00:00:00 2001 From: vincentdarley Date: Tue, 9 Mar 2004 12:56:58 +0000 Subject: glob -path fix for near filesystem root --- ChangeLog | 5 +++++ generic/tclFileName.c | 12 +++++++++++- tests/fileName.test | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ac0f03..7d97710 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-03-08 Vince Darley + + * generic/tclFileName.c: Fix to 'glob -path' near the root + * tests/fileName.test: of the filesystem. [Bug 910525] + 2004-03-01 Don Porter *** 8.4.6 TAGGED FOR RELEASE *** diff --git a/generic/tclFileName.c b/generic/tclFileName.c index bc314cf..7fbfb7f 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.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: tclFileName.c,v 1.40.2.6 2004/01/13 17:26:42 dgp Exp $ + * RCS: @(#) $Id: tclFileName.c,v 1.40.2.7 2004/03/09 12:56:59 vincentdarley Exp $ */ #include "tclInt.h" @@ -1717,6 +1717,16 @@ Tcl_GlobObjCmd(dummy, interp, objc, objv) /* Have to split off the end */ Tcl_DStringAppend(&pref, last, first+pathlength-last); pathOrDir = Tcl_NewStringObj(first, last-first-1); + /* + * We must ensure that we haven't cut off too much, + * and turned a valid path like '/' or 'C:/' into + * an incorrect path like '' or 'C:'. The way we + * do this is to add a separator if there are none + * presently in the prefix. + */ + if (strpbrk(Tcl_GetString(pathOrDir), "\\/") == NULL) { + Tcl_AppendToObj(pathOrDir, last-1, 1); + } } /* Need to quote 'prefix' */ Tcl_DStringInit(&prefix); diff --git a/tests/fileName.test b/tests/fileName.test index 830618b..db431fc 100644 --- a/tests/fileName.test +++ b/tests/fileName.test @@ -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: fileName.test,v 1.30.2.3 2003/10/06 09:49:20 vincentdarley Exp $ +# RCS: @(#) $Id: fileName.test,v 1.30.2.4 2004/03/09 12:56:59 vincentdarley Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -1648,6 +1648,37 @@ test filename-12.5 {simple globbing} { test filename-12.6 {simple globbing} { list [catch {glob globTest\\/\\x1.c} msg] $msg } "0 $globPreResult$x1" +test filename-12.7 {globbing at filesystem root} {unixOnly} { + set res1 [glob -nocomplain /*] + set res2 [glob -path / *] + set equal [string equal $res1 $res2] + if {!$equal} { + lappend equal "not equal" $res1 $res2 + } + set equal +} {1} +test filename-12.8 {globbing at filesystem root} {unixOnly} { + set dir [lindex [glob -type d /*] 0] + set first [string range $dir 0 1] + set res1 [glob -nocomplain ${first}*] + set res2 [glob -path $first *] + set equal [string equal $res1 $res2] + if {!$equal} { + lappend equal "not equal" $res1 $res2 + } + set equal +} {1} +test filename-12.9 {globbing at filesystem root} {winOnly} { + set dir [lindex [glob -type d [lindex [file volumes] 0]*] 0] + set first [string range $dir 0 3] + set res1 [glob -nocomplain ${first}*] + set res2 [glob -path $first *] + set equal [string equal $res1 $res2] + if {!$equal} { + lappend equal "not equal" $res1 $res2 + } + set equal +} {1} test filename-13.1 {globbing with brace substitution} { list [catch {glob globTest/\{\}} msg] $msg -- cgit v0.12