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