Index: src/OFURL.h ================================================================== --- src/OFURL.h +++ src/OFURL.h @@ -45,10 +45,18 @@ @property (copy) OFString *parameters; @property (copy) OFString *query; @property (copy) OFString *fragment; #endif +/*! + * Creates a new URL. + * + * @param string A string describing a URL + * @return A new, autoreleased OFURL + */ ++ (instancetype)URL; + /*! * Creates a new URL with the specified string. * * @param string A string describing a URL * @return A new, autoreleased OFURL Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -76,10 +76,15 @@ return [ret autorelease]; } @implementation OFURL ++ (instancetype)URL +{ + return [[[self alloc] init] autorelease]; +} + + (instancetype)URLWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; } @@ -511,29 +516,33 @@ OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://", scheme]; BOOL needPort = YES; if ([scheme isEqual: @"file"]) { - [ret appendString: path]; + if (path != nil) + [ret appendString: path]; + return ret; } if (user != nil && password != nil) [ret appendFormat: @"%@:%@@", user, password]; else if (user != nil) [ret appendFormat: @"%@@", user]; - [ret appendString: host]; + if (host != nil) + [ret appendString: host]; if (([scheme isEqual: @"http"] && port == 80) || ([scheme isEqual: @"https"] && port == 443)) needPort = NO; if (needPort) [ret appendFormat: @":%d", port]; - [ret appendString: path]; + if (path != nil) + [ret appendString: path]; if (parameters != nil) [ret appendFormat: @";%@", parameters]; if (query != nil)