From 1afac41537a3c130ac250f25e5ab5d29ce31878b Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 7 Jan 2010 16:59:41 +0000 Subject: [PATCH] Monotone-Parent: 1e9c4371dcc93fa8a7f07290f63d3623a276fb8e Monotone-Revision: 53583144c5d999d03c432c06fcea467dcb2b4988 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-01-07T16:59:41 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 ++ SoObjects/SOGo/NSDictionary+BSJSONAdditions.m | 2 +- UnitTests/TestBSJSONAdditions.m | 43 ++++++++++++++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35ef54d4e..2343860e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2010-01-07 Wolfgang Sourdeau + * SoObjects/SOGo/NSDictionary+BSJSONAdditions.m + (-jsonStringFromString:): convert "\" to "\\" rather than "\n". + * SoObjects/SOGo/NSScanner+BSJSONAdditions.m (-scanJSONString): we now accept lowercase characters in characters coded in UCN. diff --git a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m index 7371143f4..729d9df41 100644 --- a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m +++ b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m @@ -137,7 +137,7 @@ const int jsonDoNotIndent = -1; [jsonString appendString:@"\\\""]; break; case '\\': - [jsonString appendString:@"\\n"]; + [jsonString appendString:@"\\\\"]; break; /* TODO: email out to json group on this - spec says to handlt his, examples and example code don't handle this. case '\/': diff --git a/UnitTests/TestBSJSONAdditions.m b/UnitTests/TestBSJSONAdditions.m index 2a35328f7..1cd5c5583 100644 --- a/UnitTests/TestBSJSONAdditions.m +++ b/UnitTests/TestBSJSONAdditions.m @@ -23,26 +23,27 @@ #import #import -#import +#import "SOGo/NSScanner+BSJSONAdditions.h" +#import "SOGo/NSDictionary+BSJSONAdditions.h" #import "SOGoTest.h" -@interface TestBSJSONAdditions : SOGoTest +@interface TestNSSCannerBSJSONAdditions : SOGoTest @end -@implementation TestBSJSONAdditions +@implementation TestNSSCannerBSJSONAdditions - (void) test_scanJSONString { NSScanner *testScanner; + NSString *currentString, *expected, *error; + NSMutableString *resultString; + int count; NSString *testStrings[] = { @"\"\\\\\"", @"\\", @"\"\\u0041\"", @"A", @"\"\\u000A\"", @"\n", @"\"\\u000a\"", @"\n", nil }; - NSString *currentString, *expected, *error; - NSMutableString *resultString; - int count; count = 0; while ((currentString = testStrings[count * 2])) @@ -60,3 +61,33 @@ } @end + +@interface TestNSDictionaryBSJSONAdditions : SOGoTest +@end + +@implementation TestNSDictionaryBSJSONAdditions + +- (void) test_jsonStringForString +{ + NSDictionary *testDictionary; + NSString *currentString, *resultString, *expected, *error; + int count; + NSString *testStrings[] = { @"\n", @"\"\\n\"", + @"\\", @"\"\\\\\"", + nil }; + + testDictionary = [NSDictionary dictionary]; + count = 0; + while ((currentString = testStrings[count * 2])) + { + resultString = [testDictionary jsonStringForString: currentString]; + expected = testStrings[count * 2 + 1]; + error = [NSString stringWithFormat: + @"objects '%@' and '%@' differs (count: %d)", + expected, resultString, count]; + testEqualsWithMessage(expected, resultString, error); + count++; + } +} + +@end