Index: src/OFURL.h ================================================================== --- src/OFURL.h +++ src/OFURL.h @@ -39,15 +39,27 @@ /*! * The scheme part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *scheme; +/*! + * The scheme part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedScheme; + /*! * The host part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host; +/*! + * The host part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedHost; + /*! * The port part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port; @@ -54,20 +66,38 @@ /*! * The user part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user; +/*! + * The user part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedUser; + /*! * The password part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password; +/*! + * The password part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedPassword; + /*! * The path part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *path; +/*! + * The path part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedPath; + /*! * The path of the URL split into components. * * The first component must always be empty to designate the root. */ @@ -85,15 +115,27 @@ /*! * The query part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query; +/*! + * The query part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedQuery; + /*! * The fragment part of the URL. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment; +/*! + * The fragment part of the URL in URL-encoded form. + */ +@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) + OFString *URLEncodedFragment; + /*! * The URL as a string. */ @property (readonly, nonatomic) OFString *string; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -396,15 +396,25 @@ - (OFString *)scheme { return _scheme; } + +- (OFString *)URLEncodedScheme +{ + return [_scheme stringByURLEncoding]; +} - (OFString *)host { return _host; } + +- (OFString *)URLEncodedHost +{ + return [_host stringByURLEncoding]; +} - (OFNumber *)port { return _port; } @@ -411,20 +421,36 @@ - (OFString *)user { return _user; } + +- (OFString *)URLEncodedUser +{ + return [_user stringByURLEncoding]; +} - (OFString *)password { return _password; } + +- (OFString *)URLEncodedPassword +{ + return [_password stringByURLEncoding]; +} - (OFString *)path { return _path; } + +- (OFString *)URLEncodedPath +{ + return [_path stringByURLEncodingWithAllowedCharacters: + "-._~!$&'()*+,;=:@/"]; +} - (OFArray *)pathComponents { return [_path componentsSeparatedByString: @"/"]; } @@ -471,15 +497,27 @@ - (OFString *)query { return _query; } + +- (OFString *)URLEncodedQuery +{ + return [_query stringByURLEncodingWithAllowedCharacters: + "-._~!$&'()*+,;=:@/?"]; +} - (OFString *)fragment { return _fragment; } + +- (OFString *)URLEncodedFragment +{ + return [_fragment stringByURLEncodingWithAllowedCharacters: + "-._~!$&'()*+,;=:@/?"]; +} - (id)copy { return [self retain]; } @@ -508,42 +546,36 @@ - (OFString *)string { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); - [ret appendFormat: @"%@://", [_scheme stringByURLEncoding]]; + [ret appendFormat: @"%@://", [self URLEncodedScheme]]; if (_user != nil && _password != nil) [ret appendFormat: @"%@:%@@", - [_user stringByURLEncoding], - [_password stringByURLEncoding]]; + [self URLEncodedUser], + [self URLEncodedPassword]]; else if (_user != nil) - [ret appendFormat: @"%@@", [_user stringByURLEncoding]]; + [ret appendFormat: @"%@@", [self URLEncodedUser]]; if (_host != nil) - [ret appendString: [_host stringByURLEncoding]]; + [ret appendString: [self URLEncodedHost]]; if (_port != nil) [ret appendFormat: @":%@", _port]; if (_path != nil) { if (![_path hasPrefix: @"/"]) @throw [OFInvalidFormatException exception]; - [ret appendString: [_path - stringByURLEncodingWithAllowedCharacters: - "-._~!$&'()*+,;=:@/"]]; + [ret appendString: [self URLEncodedPath]]; } if (_query != nil) - [ret appendFormat: @"?%@", - [_query stringByURLEncodingWithAllowedCharacters: - "-._~!$&'()*+,;=:@/?"]]; + [ret appendFormat: @"?%@", [self URLEncodedQuery]]; if (_fragment != nil) - [ret appendFormat: @"#%@", - [_fragment stringByURLEncodingWithAllowedCharacters: - "-._~!$&'()*+,;=:@/?"]]; + [ret appendFormat: @"#%@", [self URLEncodedFragment]]; objc_autoreleasePoolPop(pool); [ret makeImmutable];