Fix crash when identical keys appear in a URL encoded string that is decoded into a dictionary. Add test coverage

This commit is contained in:
Blake Watters
2012-10-04 18:31:51 -04:00
parent 82ff81222a
commit a85e209d54
2 changed files with 20 additions and 1 deletions

View File

@@ -58,7 +58,6 @@ NSDictionary *RKDictionaryFromURLEncodedStringWithEncoding(NSString *URLEncodedS
} else {
[queryComponents setObject:value forKey:key];
}
[results addObject:value];
}
return queryComponents;
}

View File

@@ -20,6 +20,8 @@
#import "RKTestEnvironment.h"
#import "RKURLEncodedSerialization.h"
#define EXP_SHORTHAND
#import "Expecta.h"
@interface RKURLEncodedSerializationTest : RKTestCase
@@ -96,4 +98,22 @@
assertThat(queryParameters, hasEntries(@"keyA", @"valA", @"keyB", @"valB", nil));
}
- (void)testDictionaryFromURLEncodedStringWithSimpleKeyValues
{
NSString *query = @"this=that&keyA=valueB";
NSDictionary *dictionary = RKDictionaryFromURLEncodedStringWithEncoding(query, NSUTF8StringEncoding);
expect(@"foo").to.equal(@"foo");
NSDictionary *expectedDictionary = @{ @"this": @"that", @"keyA": @"valueB" };
expect(dictionary).to.equal(expectedDictionary);
}
- (void)testDictionaryFromURLEncodedStringWithArrayValues
{
NSString *query = @"this=that&this=theOther";
NSDictionary *dictionary = RKDictionaryFromURLEncodedStringWithEncoding(query, NSUTF8StringEncoding);
expect(@"foo").to.equal(@"foo");
NSDictionary *expectedDictionary = @{ @"this": @[ @"that", @"theOther" ] };
expect(dictionary).to.equal(expectedDictionary);
}
@end