From 8c2e3f37b3163b42492fe77dfcb32af692203db7 Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Thu, 19 Nov 2015 18:09:44 +0100 Subject: [PATCH 1/2] [BUGFIX] Fixed the bug with wrong string encoding. I just added a invertedSet for the NSCharacterSet to fix this issue --- PINCache/PINDiskCache.m | 2 +- tests/PINCacheTests/PINCacheTests.m | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PINCache/PINDiskCache.m b/PINCache/PINDiskCache.m index ca93bacf..0ded6757 100644 --- a/PINCache/PINDiskCache.m +++ b/PINCache/PINDiskCache.m @@ -143,7 +143,7 @@ - (NSString *)encodedString:(NSString *)string { if (![string length]) return @""; - return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@".:/"]]; + return [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/"] invertedSet]]; } - (NSString *)decodedString:(NSString *)string diff --git a/tests/PINCacheTests/PINCacheTests.m b/tests/PINCacheTests/PINCacheTests.m index e9672bbf..3bd5703a 100644 --- a/tests/PINCacheTests/PINCacheTests.m +++ b/tests/PINCacheTests/PINCacheTests.m @@ -62,6 +62,12 @@ - (dispatch_time_t)timeout #pragma mark - Tests - +- (void)testDiskCacheStringEncoding +{ + NSString *string = [@"http://www.test.de-" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/"] invertedSet]]; + XCTAssertTrue([string isEqualToString:@"http%3A%2F%2Fwww%2Etest%2Ede-"]); +} + - (void)testCoreProperties { PINCache *cache = [[PINCache alloc] initWithName:PINCacheTestName]; From 3391c577e00fc41365463ecc12b87fef6948d69d Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Thu, 19 Nov 2015 18:20:53 +0100 Subject: [PATCH 2/2] created the unit test with test wrapper for encodeString --- tests/PINCacheTests/PINCacheTests.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/PINCacheTests/PINCacheTests.m b/tests/PINCacheTests/PINCacheTests.m index 3bd5703a..c9ff7665 100644 --- a/tests/PINCacheTests/PINCacheTests.m +++ b/tests/PINCacheTests/PINCacheTests.m @@ -8,6 +8,12 @@ NSString * const PINCacheTestName = @"PINCacheTest"; NSTimeInterval PINCacheTestBlockTimeout = 5.0; +@interface PINDiskCache() + +- (NSString *)encodedString:(NSString *)string; + +@end + @interface PINCacheTests () @property (strong, nonatomic) PINCache *cache; @end @@ -64,7 +70,7 @@ - (dispatch_time_t)timeout - (void)testDiskCacheStringEncoding { - NSString *string = [@"http://www.test.de-" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/"] invertedSet]]; + NSString *string = [self.cache.diskCache encodedString:@"http://www.test.de-"]; XCTAssertTrue([string isEqualToString:@"http%3A%2F%2Fwww%2Etest%2Ede-"]); }