diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 17e3d14bb..5884be2ea 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -299,7 +299,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 2760de479..0904858a6 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -250,4 +250,13 @@ [self assertTrue:d.indexOf("y: 6") !== -1 message:"Can't find 'y: 6' in description of dictionary " + d]; } +- (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