diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 7c58ff1de..dc0dc5307 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -300,7 +300,7 @@ var value = arguments[index]; if (value === nil) - break; + continue; [self setObject:value forKey:arguments[index + 1]]; } diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j index 685f2cdb3..a810aefbc 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -399,4 +399,13 @@ [self assert:'@{\n @"key1": @[\n @"1",\n @"2",\n @"3"\n ],\n @"key2": @"This is a string",\n @"key3": @{\n @"another": @"object"\n }\n}' equals:[json_dict description]]; } +- (void)testInitWithObjectsAndKeys +{ + var dict = [[CPDictionary alloc] initWithObjectsAndKeys:@"Value1", @"Key1", nil, @"Key2", @"Value3", @"Key3"]; + + [self assert:2 equals:[dict count]]; + [self assert:@"Value1" equals:[dict objectForKey:@"Key1"]]; + [self assert:nil equals:[dict objectForKey:@"Key2"]]; // No key/value pair + [self assert:@"Value3" equals:[dict objectForKey:@"Key3"]]; +} @end