Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -99,13 +99,13 @@ @throw [OFInvalidFormatException exception]; for (tmp2 = UTF8String; tmp2 < tmp; tmp2++) *tmp2 = of_ascii_tolower(*tmp2); - _scheme = [[OFString alloc] - initWithUTF8String: UTF8String - length: tmp - UTF8String]; + _scheme = [[[OFString stringWithUTF8String: UTF8String + length: tmp - UTF8String] + stringByURLDecoding] copy]; UTF8String = tmp + 3; if ((tmp = strchr(UTF8String, '/')) != NULL) { *tmp = '\0'; @@ -120,17 +120,17 @@ if ((tmp3 = strchr(UTF8String, ':')) != NULL) { *tmp3 = '\0'; tmp3++; - _user = [[OFString alloc] - initWithUTF8String: UTF8String]; - _password = [[OFString alloc] - initWithUTF8String: tmp3]; + _user = [[[OFString stringWithUTF8String: + UTF8String] stringByURLDecoding] copy]; + _password = [[[OFString stringWithUTF8String: + tmp3] stringByURLDecoding] copy]; } else - _user = [[OFString alloc] - initWithUTF8String: UTF8String]; + _user = [[[OFString stringWithUTF8String: + UTF8String] stringByURLDecoding] copy]; UTF8String = tmp2; } if ((tmp2 = strchr(UTF8String, ':')) != NULL) { @@ -138,12 +138,12 @@ OFString *portString; *tmp2 = '\0'; tmp2++; - _host = [[OFString alloc] - initWithUTF8String: UTF8String]; + _host = [[[OFString stringWithUTF8String: UTF8String] + stringByURLDecoding] copy]; pool2 = objc_autoreleasePoolPush(); portString = [OFString stringWithUTF8String: tmp2]; if ([portString decimalValue] > 65535) @@ -152,40 +152,40 @@ _port = [[OFNumber alloc] initWithUInt16: (uint16_t)[portString decimalValue]]; objc_autoreleasePoolPop(pool2); } else - _host = [[OFString alloc] - initWithUTF8String: UTF8String]; + _host = [[[OFString stringWithUTF8String: UTF8String] + stringByURLDecoding] copy]; if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; - _fragment = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _fragment = [[[OFString stringWithUTF8String: + tmp + 1] stringByURLDecoding] copy]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; - _query = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _query = [[[OFString stringWithUTF8String: + tmp + 1] stringByURLDecoding] copy]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; - _parameters = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _parameters = [[[OFString stringWithUTF8String: + tmp + 1] stringByURLDecoding] copy]; } UTF8String--; *UTF8String = '/'; - _path = [[OFString alloc] - initWithUTF8String: UTF8String]; + _path = [[[OFString stringWithUTF8String: UTF8String] + stringByURLDecoding] copy]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @@ -224,33 +224,34 @@ UTF8String = UTF8String2; if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; - _fragment = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _fragment = [[[OFString stringWithUTF8String: tmp + 1] + stringByURLDecoding] copy]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; - _query = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _query = [[[OFString stringWithUTF8String: tmp + 1] + stringByURLDecoding] copy]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; - _parameters = [[OFString alloc] - initWithUTF8String: tmp + 1]; + _parameters = [[[OFString stringWithUTF8String: tmp + 1] + stringByURLDecoding] copy]; } if (*UTF8String == '/') - _path = [[OFString alloc] - initWithUTF8String: UTF8String]; + _path = [[[OFString stringWithUTF8String: UTF8String] + stringByURLDecoding] copy]; else { OFString *path, *s; - path = [OFString stringWithUTF8String: UTF8String]; + path = [[OFString stringWithUTF8String: UTF8String] + stringByURLDecoding]; if ([URL->_path hasSuffix: @"/"]) s = [URL->_path stringByAppendingString: path]; else s = [OFString stringWithFormat: @"%@/../%@", @@ -531,37 +532,40 @@ - (OFString *)string { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); - [ret appendFormat: @"%@://", _scheme]; + [ret appendFormat: @"%@://", [_scheme stringByURLEncoding]]; if (_user != nil && _password != nil) - [ret appendFormat: @"%@:%@@", _user, _password]; + [ret appendFormat: @"%@:%@@", + [_user stringByURLEncoding], + [_password stringByURLEncoding]]; else if (_user != nil) - [ret appendFormat: @"%@@", _user]; + [ret appendFormat: @"%@@", [_user stringByURLEncoding]]; if (_host != nil) - [ret appendString: _host]; + [ret appendString: [_host stringByURLEncoding]]; if (_port != nil) [ret appendFormat: @":%@", _port]; if (_path != nil) { if (![_path hasPrefix: @"/"]) @throw [OFInvalidFormatException exception]; - [ret appendString: _path]; + [ret appendString: [_path + stringByURLEncodingWithAllowedCharacters: "$-_.!*()/"]]; } if (_parameters != nil) - [ret appendFormat: @";%@", _parameters]; + [ret appendFormat: @";%@", [_parameters stringByURLEncoding]]; if (_query != nil) - [ret appendFormat: @"?%@", _query]; + [ret appendFormat: @"?%@", [_query stringByURLEncoding]]; if (_fragment != nil) - [ret appendFormat: @"#%@", _fragment]; + [ret appendFormat: @"#%@", [_fragment stringByURLEncoding]]; objc_autoreleasePoolPop(pool); [ret makeImmutable]; Index: tests/OFURLTests.m ================================================================== --- tests/OFURLTests.m +++ tests/OFURLTests.m @@ -28,11 +28,11 @@ #import "OFInvalidFormatException.h" #import "TestsAppDelegate.h" static OFString *module = @"OFURL"; -static OFString *url_str = @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/" +static OFString *url_str = @"ht%3Atp://us%3Aer:p%40w@ho%3Ast:1234/" @"pa%3Bth;pa%3Fram?que%23ry#frag%23ment"; @implementation TestsAppDelegate (OFURLTests) - (void)URLTests { @@ -46,11 +46,11 @@ R(u4 = [OFURL URLWithString: @"file:///etc/passwd"])) TEST(@"+[URLWithString:relativeToURL:]", [[[OFURL URLWithString: @"/foo" relativeToURL: u1] string] isEqual: - @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/foo"] && + @"ht%3Atp://us%3Aer:p%40w@ho%3Ast:1234/foo"] && [[[OFURL URLWithString: @"foo/bar?q" relativeToURL: [OFURL URLWithString: @"http://h/qux/quux"]] string] isEqual: @"http://h/qux/foo/bar?q"] && [[[OFURL URLWithString: @"foo/bar" relativeToURL: [OFURL URLWithString: @"http://h/qux/?x"]] @@ -70,23 +70,23 @@ [[u2 string] isEqual: @"http://foo:80"] && [[u3 string] isEqual: @"http://bar/"] && [[u4 string] isEqual: @"file:///etc/passwd"]) TEST(@"-[scheme]", - [[u1 scheme] isEqual: @"ht%3atp"] && [[u4 scheme] isEqual: @"file"]) + [[u1 scheme] isEqual: @"ht:tp"] && [[u4 scheme] isEqual: @"file"]) - TEST(@"-[user]", [[u1 user] isEqual: @"us%3Aer"] && [u4 user] == nil) + TEST(@"-[user]", [[u1 user] isEqual: @"us:er"] && [u4 user] == nil) TEST(@"-[password]", - [[u1 password] isEqual: @"p%40w"] && [u4 password] == nil) - TEST(@"-[host]", [[u1 host] isEqual: @"ho%3Ast"] && [u4 port] == 0) + [[u1 password] isEqual: @"p@w"] && [u4 password] == nil) + TEST(@"-[host]", [[u1 host] isEqual: @"ho:st"] && [u4 port] == 0) TEST(@"-[port]", [[u1 port] isEqual: [OFNumber numberWithUInt16: 1234]]) TEST(@"-[path]", - [[u1 path] isEqual: @"/pa%3Bth"] && + [[u1 path] isEqual: @"/pa;th"] && [[u4 path] isEqual: @"/etc/passwd"]) TEST(@"-[pathComponents]", [[u1 pathComponents] isEqual: - [OFArray arrayWithObjects: @"", @"pa%3Bth", nil]] && + [OFArray arrayWithObjects: @"", @"pa;th", nil]] && [[u4 pathComponents] isEqual: [OFArray arrayWithObjects: @"", @"etc", @"passwd", nil]]) TEST(@"-[lastPathComponent", [[[OFURL URLWithString: @"http://host/foo//bar/baz"] lastPathComponent] isEqual: @"baz"] && @@ -95,15 +95,15 @@ [[[OFURL URLWithString: @"http://host/foo/"] lastPathComponent] isEqual: @"foo"] && [[[OFURL URLWithString: @"http://host/"] lastPathComponent] isEqual: @""]) TEST(@"-[parameters]", - [[u1 parameters] isEqual: @"pa%3Fram"] && [u4 parameters] == nil) + [[u1 parameters] isEqual: @"pa?ram"] && [u4 parameters] == nil) TEST(@"-[query]", - [[u1 query] isEqual: @"que%23ry"] && [u4 query] == nil) + [[u1 query] isEqual: @"que#ry"] && [u4 query] == nil) TEST(@"-[fragment]", - [[u1 fragment] isEqual: @"frag%23ment"] && [u4 fragment] == nil) + [[u1 fragment] isEqual: @"frag#ment"] && [u4 fragment] == nil) TEST(@"-[copy]", R(u4 = [[u1 copy] autorelease])) TEST(@"-[isEqual:]", [u1 isEqual: u4] && ![u2 isEqual: u3] && [[OFURL URLWithString: @"HTTP://bar/"] isEqual: u3])