From e698f247ee01f8ce88d89a3d5186bbf1156efb12 Mon Sep 17 00:00:00 2001 From: CaS Date: Thu, 31 Mar 2005 19:47:41 +0000 Subject: [PATCH] More tweaks to isAbsolute git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21023 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 ++- Headers/Foundation/NSString.h | 6 ++--- Source/NSString.m | 47 +++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c0e6b286..668426757 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,9 @@ * Source/NSString.m: (isAbsolutePath) always treat a path beginning with '/' as absolute except when in windows mode or on windows and - not in unix mode. + not in unix mode. Treat all UNC paths as absolute ... a change made + after a lot of trawling the web and looking at examples of UNC path + usage. 2005-03-23 Richard Frith-Macdonald diff --git a/Headers/Foundation/NSString.h b/Headers/Foundation/NSString.h index 865d23e99..8017d86ce 100644 --- a/Headers/Foundation/NSString.h +++ b/Headers/Foundation/NSString.h @@ -539,9 +539,9 @@ enum { * Returns NO otherwise.
* An absolute path in unix mode is one which begins * with a slash or tilde.
- * In windows mode a drive specification (eg C:) or a UNC server and share - * (eg //host/share) followed by a slash or backslash, is an absolute path, - * as is any path beginning with a tilde.
+ * In windows mode a drive specification (eg C:) followed by a slash or + * backslash, is an absolute path, as is any path beginning with a tilde.
+ * In any mode a UNC path (//host/share...) is always absolute.
* In gnustep path handling mode, the rules are the same as for windows, * except that a path whose root is a slash denotes an absolute path * when running on unix and a relative path when running under windows. diff --git a/Source/NSString.m b/Source/NSString.m index 8b5d812b1..faf800272 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -4405,34 +4405,49 @@ static NSFileManager *fm = nil; if (l == 0) { - return NO; // Empty string ... not absolute + return NO; // Empty string ... relative } c = [self characterAtIndex: 0]; if (c == (unichar)'~') { return YES; // Begins with tilde ... absolute } -#if !defined(__MINGW__) - if (c == '/' && GSPathHandlingWindows() == NO) - { - return YES; // Begins with slash ... absolute on unix. - } -#endif - root = rootOf(self, l); - if (root > 0 && pathSepMember([self characterAtIndex: root-1])) + + /* + * Any string beginning with '/' is absolute ... except in windows mode + * or on windows and not in unix mode. + */ + if (c == '/') { #if defined(__MINGW__) - if (root == 1 && GSPathHandlingUnix() == NO) + if (GSPathHandlingUnix() == YES) { - return NO; // Single slash/backslash is not absolute. + return YES; + } +#else + if (GSPathHandlingWindows() == NO) + { + return YES; } #endif - if (root == 1 && c == '\\') - { - return NO; // Single backslash is not absolute - } - return YES; // Root ends with separator ... absolute. + } + + /* + * Any root over two characters long must be a drive specification with a + * slash (absolute) or a UNC path (always absolute). + */ + root = rootOf(self, l); + if (root > 2) + { + return YES; // UNC or C:/ ... absolute } + + /* + * What we have left are roots of the form 'C:' or '\' or a path + * with no root, or a '/' (in windows mode only sence we already + * handled a single slash in unix mode) ... + * all these cases are relative paths. + */ return NO; }