iHacks for MacOS-X compatibility

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14322 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-08-24 06:00:44 +00:00
parent e851388aa5
commit 86b2121e5d
3 changed files with 64 additions and 15 deletions

View file

@ -1,7 +1,14 @@
2002-08-23 Richard Frith-Macdonald <rfm@gnu.org>
2002-08-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURL.m: Hack for compatibility with MacOS-X in returning
path of a file URL ... the RFC says we shouldn't.
* Source/NSURL.m: Hacks for compatibility with MacOS-X in returning
path of a file URL ... the RFC says we shouldn't, but MacOS-X does.
Also when creating relative file URLs the MacOS-X code doesn't
strip the last patch component of the base URL as it should ...
we emulate that too.
Final note ... the MacOS-X code inserts 'localhost' as a host name
for a file URL which it shouldnt (a file URL has no host part) but
we don't emulate that at present (perhaps never as I can't see it
being very useful).
2002-08-22 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -72,6 +72,7 @@ typedef struct {
BOOL pathIsAbsolute;
BOOL hasNoPath;
BOOL isGeneric;
BOOL isFile;
} parsedURL;
#define myData ((parsedURL*)(self->_data))
@ -210,7 +211,26 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
else
{
char *start = base->path;
char *end = strrchr(start, '/');
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, '/');
}
if (end != 0)
{
@ -662,6 +682,7 @@ static void unescape(const char *from, char * to)
usesFragments = NO;
usesParameters = NO;
usesQueries = NO;
buf->isFile = YES;
}
else if (strcmp(buf->scheme, "mailto") == 0)
{
@ -1059,11 +1080,7 @@ static void unescape(const char *from, char * to)
*/
- (BOOL) isFileURL
{
if (myData->scheme != 0 && strcmp(myData->scheme, "file") == 0)
{
return YES;
}
return NO;
return myData->isFile;
}
/**
@ -1186,7 +1203,7 @@ static void unescape(const char *from, char * to)
/*
* If this scheme is from a URL without generic format, there is no path.
*/
if (myData->isGeneric == YES)
if (myData->isGeneric == YES || myData->isFile == YES)
{
unsigned int len = (_baseURL ? strlen(baseData->path) : 0)
+ strlen(myData->path) + 3;
@ -1231,11 +1248,6 @@ static void unescape(const char *from, char * to)
unescape(buf, buf);
path = [NSString stringWithUTF8String: buf];
}
else if (myData->scheme != 0 && myData->path != 0
&& strcmp(myData->scheme, "file") == 0)
{
path = [NSString stringWithUTF8String: myData->path];
}
return path;
}

View file

@ -3,12 +3,42 @@
#if 1
static void test1(void)
{
NSURL *baseURL = [NSURL fileURLWithPath:@"/usr/local/bin"];
NSURL *url = [NSURL URLWithString:@"filename" relativeToURL:baseURL];
NSString *result = [url absoluteString];
NSString *expected = @"file:/usr/local/bin/filename";
if ([result isEqualToString:expected])
NSLog(@"test 1 ok");
else
NSLog(@"-[NSURL absoluteString] returned \"%@\", expected \"%@\"", result, expected);
}
static void test2(void)
{
NSURL *url = [NSURL fileURLWithPath:@"/tmp/foo"];
NSString *result = [url path];
NSString *expected = @"/tmp/foo";
if ([result isEqualToString:expected])
NSLog(@"Test 2 ok");
else
NSLog(@"-[NSURL path] returned \"%@\", expected \"%@\"", result, expected);
}
int main ()
{
id pool = [NSAutoreleasePool new];
id o = [NSObject new];
NSArray *a = [NSArray arrayWithObjects: @"a", @"b", nil];
test1();
test2();
printf ("Hello from object at 0x%x\n", (unsigned)[o self]);
NSLog(@"Value for foo is %@", [a valueForKey: @"foo"]);