From 23401d37d80697c8bbd224c73f3024a7ed6390c0 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 14 Sep 2012 10:54:41 +0200 Subject: [PATCH] Fixed error in function CPDescriptionOfObject when a JSON object property has a null value. The function can't handle the following JSON object: {name:null}. Also added a test case for this. --- Foundation/CPObject.j | 3 +++ Tests/Foundation/CPObjectTest.j | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 5590a2048..d47d522ed 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -532,6 +532,9 @@ CPLog(@"Got some class: %@", inst); function CPDescriptionOfObject(anObject) { + if (!anObject) + return String(anObject); + if (anObject.isa) { if ([anObject isKindOfClass:CPString]) diff --git a/Tests/Foundation/CPObjectTest.j b/Tests/Foundation/CPObjectTest.j index 5b8f487de..926a00238 100644 --- a/Tests/Foundation/CPObjectTest.j +++ b/Tests/Foundation/CPObjectTest.j @@ -50,6 +50,15 @@ [self assertTrue:expectedReturnValue === returnValue]; } +- (void)testCPDescriptionOfObject +{ + var jSON = {"name": "Martin", "access":null}, + d = CPDescriptionOfObject(jSON); + + [self assertTrue:d.indexOf("name:") !== -1 message:"Can't find 'name:' in description of json " + d]; + [self assertTrue:d.indexOf("access:") !== -1 message:"Can't find 'access:' in description of json " + d]; +} + @end @implementation SuperReceiver : CPObject