From a85e209d546e8ff20fa57e09b853573bda2f284c Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Thu, 4 Oct 2012 18:31:51 -0400 Subject: [PATCH] Fix crash when identical keys appear in a URL encoded string that is decoded into a dictionary. Add test coverage --- Code/Support/RKURLEncodedSerialization.m | 1 - .../Support/RKURLEncodedSerializationTest.m | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Code/Support/RKURLEncodedSerialization.m b/Code/Support/RKURLEncodedSerialization.m index 374afaac..2433a91e 100644 --- a/Code/Support/RKURLEncodedSerialization.m +++ b/Code/Support/RKURLEncodedSerialization.m @@ -58,7 +58,6 @@ NSDictionary *RKDictionaryFromURLEncodedStringWithEncoding(NSString *URLEncodedS } else { [queryComponents setObject:value forKey:key]; } - [results addObject:value]; } return queryComponents; } diff --git a/Tests/Logic/Support/RKURLEncodedSerializationTest.m b/Tests/Logic/Support/RKURLEncodedSerializationTest.m index df54b95a..7b9919f6 100644 --- a/Tests/Logic/Support/RKURLEncodedSerializationTest.m +++ b/Tests/Logic/Support/RKURLEncodedSerializationTest.m @@ -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