diff --git a/ChangeLog b/ChangeLog index bf042d500..7de6f89d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-08-24 Richard Frith-Macdonald + + * Source/NSURL.m: ([-initFileURLWithPath:]) check to see if path is + a directory and append a trailing slash if necessary. Remove hack + to refrain from stripping last patch component in file URLs. + 2002-08-24 Richard Frith-Macdonald * Source/NSURL.m: Hacks for compatibility with MacOS-X in returning diff --git a/Source/NSURL.m b/Source/NSURL.m index 783dcdb12..73ea121c6 100644 --- a/Source/NSURL.m +++ b/Source/NSURL.m @@ -43,6 +43,7 @@ function may be incorrect #include #include #include +#include #include #include #include @@ -211,26 +212,7 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize) else { char *start = base->path; - char *end; - - /* - * Evil hack for MacOS-X compatibility. - * RFCs state that '/foo/bar' combined with 'xxx' - * gives '/foo/xxx', but MacOS-X treats file URLs - * differently and returns '/foo/bar/xxx' - */ - if (rel->isFile == YES) - { - end = &start[strlen(start)]; - if (end > start && end[-1] == '/') - { - end--; - } - } - else - { - end = strrchr(start, '/'); - } + char *end = strrchr(start, '/'); if (end != 0) { @@ -575,11 +557,24 @@ static void unescape(const char *from, char * to) } /** - * Initialise as a file URL with the specified path.
- * Calls -initWithString:relativeToURL: + * Initialise as a file URL with the specified path (which must + * be a valid path on the local filesystem).
+ * Appends a trailing slash to the path when necessary if it + * specifies a directory.
+ * Calls -initWithScheme:host:path: */ - (id) initFileURLWithPath: (NSString*)aPath { + if ([aPath hasSuffix: @"/"] == NO) + { + BOOL flag = NO; + + if ([[NSFileManager defaultManager] fileExistsAtPath: aPath + isDirectory: &flag] == YES && flag == YES) + { + aPath = [aPath stringByAppendingString: @"/"]; + } + } self = [self initWithScheme: NSURLFileScheme host: nil path: aPath];