mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 22:51:50 +08:00
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:
@@ -58,7 +58,6 @@ NSDictionary *RKDictionaryFromURLEncodedStringWithEncoding(NSString *URLEncodedS
|
||||
} else {
|
||||
[queryComponents setObject:value forKey:key];
|
||||
}
|
||||
[results addObject:value];
|
||||
}
|
||||
return queryComponents;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user