@@ -68,12 +68,17 @@ - (void)setHost: (OFString *)host { void *pool = objc_autoreleasePoolPush(); OFString *old = _URLEncodedHost; - _URLEncodedHost = [[host stringByURLEncodingWithAllowedCharacters: - [OFCharacterSet URLHostAllowedCharacterSet]] copy]; + if (of_url_is_ipv6_host(host)) + _URLEncodedHost = [[OFString alloc] + initWithFormat: @"[%@]", host]; + else + _URLEncodedHost = [[host + stringByURLEncodingWithAllowedCharacters: + [OFCharacterSet URLHostAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } @@ -80,11 +85,16 @@ - (void)setURLEncodedHost: (OFString *)URLEncodedHost { OFString *old; - if (URLEncodedHost != nil) + if ([URLEncodedHost hasPrefix: @"["] && + [URLEncodedHost hasSuffix: @"]"]) { + if (!of_url_is_ipv6_host([URLEncodedHost substringWithRange: + of_range(1, URLEncodedHost.length - 2)])) + @throw [OFInvalidFormatException exception]; + } else if (URLEncodedHost != nil) of_url_verify_escaped(URLEncodedHost, [OFCharacterSet URLHostAllowedCharacterSet]); old = _URLEncodedHost; _URLEncodedHost = [URLEncodedHost copy];