Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 43af4e0

Browse files
committed
Remove occurrences of [].
1 parent 09c7bbf commit 43af4e0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CMDQueryStringSerialization/CMDQueryStringSerialization.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ - (void)cmd_enumeratePairs:(void (^) (NSString *key, NSString *value))block {
8282
if (range.location == NSNotFound) {
8383
key = [pair cmd_stringByRemovingEscapes];
8484
value = @"";
85-
} else {
85+
}
86+
else {
8687
key = [pair substringToIndex:range.location];
8788
key = [key cmd_stringByRemovingEscapes];
8889
value = [pair substringFromIndex:(range.location + range.length)];
8990
value = [value cmd_stringByRemovingEscapes];
9091
}
92+
key = [key stringByReplacingOccurrencesOfString:@"[]" withString:@""];
9193
block(key, value);
9294
}];
9395
}

CMDQueryStringSerializationTests/CMDQueryStringSerializationTests.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@ - (void)testQueryStringWithRepeatingParameterNoBrackets {
5656
XCTAssertEqualObjects(actualDictionary, desiredDictionary, @"Query parameters are incorrect.");
5757
}
5858

59+
60+
- (void)testQueryStringWithRepeatingParameterWithBracketsToDictionary {
61+
NSString *desiredString = @"key[]=one&key[]=two";
62+
NSDictionary *desiredDictionary = @{
63+
@"key" : @[ @"one", @"two" ]
64+
};
65+
66+
NSDictionary *actualDictionary = [CMDQueryStringSerialization dictionaryWithQueryString:desiredString];
67+
XCTAssertEqualObjects(actualDictionary, desiredDictionary, @"Query parameters are incorrect.");
68+
}
69+
5970
@end

0 commit comments

Comments
 (0)