diff --git a/ChangeLog b/ChangeLog index b35d80e9a..e61d9624e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-02-03 Richard Frith-Macdonald + + * Source/NSString.m: Fix standardising a path to use unix separators + consistently with appending a pathc component ... paths should be + (as far as possible) portable, and the filesystem representation + methods convert to backslashes as necessary on windows anyway. + 2014-02-03 Richard Frith-Macdonald * Source/Additions/GSMime.m: diff --git a/Source/NSString.m b/Source/NSString.m index ba8891297..19528f8cd 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -330,10 +330,12 @@ pathSepMember(unichar c) return NO; } -/* - * For cross-platform portability we always use slash as the separator +/* For cross-platform portability we always use slash as the separator * when building paths ... unless specific windows path handling is * required. + * This ensures that standardised paths and anything built by adding path + * components to them use a consistent separator character anad can be + * compared readily using standard string comparisons. */ inline static unichar pathSepChar() @@ -4762,14 +4764,20 @@ static NSFileManager *fm = nil; s = AUTORELEASE([self mutableCopy]); } - if (GSPathHandlingUnix() == YES) - { - [s replaceString: @"\\" withString: @"/"]; - } - else if (GSPathHandlingWindows() == YES) + /* We must always use the standard path separator unless specifically set + * to use the mswindows one. That ensures that standardised paths and + * anything built by adding path components to them use a consistent + * separator character anad can be compared readily using standard string + * comparisons. + */ + if (GSPathHandlingWindows() == YES) { [s replaceString: @"/" withString: @"\\"]; } + else + { + [s replaceString: @"\\" withString: @"/"]; + } l = [s length]; root = rootOf(s, l); diff --git a/Tests/base/NSInvocationOperation/GNUmakefile b/Tests/base/NSInvocationOperation/GNUmakefile index f16fe9867..c9d6c0ebc 100644 --- a/Tests/base/NSInvocationOperation/GNUmakefile +++ b/Tests/base/NSInvocationOperation/GNUmakefile @@ -23,5 +23,5 @@ include $(GNUSTEP_MAKEFILES)/test-tool.make -include GNUmakefile.postamble after-clean:: - rm -f core tests.log tests.sum oldtests.log oldtests.sum + rm -f core core.* *.core tests.log tests.sum oldtests.log oldtests.sum diff --git a/Tests/base/NSString/test02.m b/Tests/base/NSString/test02.m index a1d16aec4..ea57048ac 100644 --- a/Tests/base/NSString/test02.m +++ b/Tests/base/NSString/test02.m @@ -214,8 +214,7 @@ NSLog(@"Developer: %@", NSSearchPathForDirectoriesInDomains(NSDeveloperDirectory #ifdef GNUSTEP_BASE_LIBRARY - PASS_EQUAL([@"//home/user/" stringByStandardizingPath], @"//home/user/", - "//home/user/ stringByStandardizingPath == //home/user/"); + GSPathHandling("windows"); PASS_EQUAL([@"\\\\home\\user\\" stringByStandardizingPath], @"\\\\home\\user\\", @@ -226,10 +225,26 @@ NSLog(@"Developer: %@", NSSearchPathForDirectoriesInDomains(NSDeveloperDirectory PASS_EQUAL([@"c:\\..." stringByStandardizingPath], @"c:\\...", "'c:\\...' stringByStandardizingPath == 'c:\\...'"); + + PASS([@"c:\\home" isAbsolutePath] == YES, + "'c:\\home' isAbsolutePath == YES"); + + GSPathHandling("right"); + PASS_EQUAL([@"//home/user/" stringByStandardizingPath], + @"//home/user/", + "//home/user/ stringByStandardizingPath == //home/user/"); + + PASS_EQUAL([@"c:/." stringByStandardizingPath], @"c:/.", + "'c:/.' stringByStandardizingPath == 'c:/.'"); + + PASS_EQUAL([@"c:/..." stringByStandardizingPath], @"c:/...", + "'c:/...' stringByStandardizingPath == 'c:/...'"); + PASS([@"c:/home" isAbsolutePath] == YES, "'c:/home' isAbsolutePath == YES"); + PASS([@"//host/share/" isAbsolutePath] == YES, "'//host/share/' isAbsolutePath == YES");