Index: src/OFIRI.h ================================================================== --- src/OFIRI.h +++ src/OFIRI.h @@ -157,10 +157,16 @@ /** * @brief The IRI with relative subpaths resolved. */ @property (readonly, nonatomic) OFIRI *IRIByStandardizingPath; +/** + * @brief The IRI with percent-encoding applied to all Unicode characters. + */ +@property (readonly, nonatomic) + OFIRI *IRIByAddingPercentEncodingForUnicodeCharacters; + #ifdef OF_HAVE_FILES /** * @brief The local file system representation for a file IRI. * * @note This only exists for IRIs with the file scheme and throws an exception Index: src/OFIRI.m ================================================================== --- src/OFIRI.m +++ src/OFIRI.m @@ -1357,10 +1357,37 @@ - (OFIRI *)IRIByStandardizingPath { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI standardizePath]; [IRI makeImmutable]; + return IRI; +} + +- (OFIRI *)IRIByAddingPercentEncodingForUnicodeCharacters +{ + OFMutableIRI *IRI = [[self mutableCopy] autorelease]; + void *pool = objc_autoreleasePoolPush(); + OFCharacterSet *ASCII = + [OFCharacterSet characterSetWithRange: OFMakeRange(0, 0x80)]; + + IRI.percentEncodedHost = [_percentEncodedHost + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + IRI.percentEncodedUser = [_percentEncodedUser + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + IRI.percentEncodedPassword = [_percentEncodedPassword + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + IRI.percentEncodedPath = [_percentEncodedPath + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + IRI.percentEncodedQuery = [_percentEncodedQuery + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + IRI.percentEncodedFragment = [_percentEncodedFragment + stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; + + [IRI makeImmutable]; + + objc_autoreleasePoolPop(pool); + return IRI; } - (OFString *)description { Index: tests/OFIRITests.m ================================================================== --- tests/OFIRITests.m +++ tests/OFIRITests.m @@ -221,10 +221,14 @@ TEST(@"-[hash:]", IRI1.hash == IRI4.hash && IRI2.hash != IRI3.hash) EXPECT_EXCEPTION(@"Detection of invalid format", OFInvalidFormatException, [OFIRI IRIWithString: @"http"]) + TEST(@"-[IRIByAddingPercentEncodingForUnicodeCharacters]", + [IRI11.IRIByAddingPercentEncodingForUnicodeCharacters + isEqual: [OFIRI IRIWithString: @"http://%C3%A4/%C3%B6?%C3%BC"]]) + mutableIRI = [OFMutableIRI IRIWithScheme: @"dummy"]; EXPECT_EXCEPTION( @"-[setPercentEncodedScheme:] with invalid characters fails", OFInvalidFormatException, mutableIRI.scheme = @"%20")