From 8e5a26dfb15f6105d014dc3298573a25ccf75844 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 5 Jun 2013 15:53:53 -0400 Subject: [PATCH] Remove unicode separators from JSON Fixes #2309 --- NEWS | 1 + SoObjects/SOGo/NSString+Utilities.m | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index e1779ab06..7a4c5d151 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Bug fixes - Fixed decoding of the charset parameter when using single quotes (#2306) - Fixed potential crash when sending MDN from Sent folder (#2209) + - Fixed handling of unicode separators (#2309) 2.0.5a (2013-04-17) ------------------ diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 506344284..afca514b9 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -1,6 +1,6 @@ /* NSString+Utilities.m - this file is part of SOGo * - * Copyright (C) 2006-2011 Inverse inc. + * Copyright (C) 2006-2013 Inverse inc. * * Author: Wolfgang Sourdeau * Ludovic Marcotte @@ -279,24 +279,28 @@ static int cssEscapingCount; - (NSString *) jsonRepresentation { - static char thisCharCode[28]; + static unichar thisCharCode[29]; static NSString *controlCharString = nil; static NSCharacterSet *controlCharSet = nil; NSString *cleanedString; - int i; + int i, j; if (!controlCharSet) { // Create an array of chars for all control characters between 0x00 and 0x1F, // apart from \t, \n, \f and \r (0x08, 0x09, 0x0A, 0x0C and 0x0D) - for (i = 0x00; i <= 0x08; i++) { - thisCharCode[i] = i; + for (i = 0, j = 0x00; j < 0x08; i++, j++) { + thisCharCode[i] = j; } - thisCharCode[9] = 0x0B; - for (i = 0x0E; i <= 0x1F; i++) { - thisCharCode[i - 4] = i; + thisCharCode[i++] = 0x0B; + for (j = 0x0E; j <= 0x1F; i++, j++) { + thisCharCode[i] = j; } - controlCharString = [NSString stringWithCString: thisCharCode length: 28]; + + // Also add some unicode separators + thisCharCode[i++] = 0x2028; // line separator + thisCharCode[i++] = 0x2029; // paragraph separator + controlCharString = [NSString stringWithCharacters:thisCharCode length:i]; controlCharSet = [NSCharacterSet characterSetWithCharactersInString: controlCharString]; [controlCharSet retain]; } @@ -304,7 +308,6 @@ static int cssEscapingCount; // Escape double quotes and remove control characters cleanedString = [[[self doubleQuotedString] componentsSeparatedByCharactersInSet: controlCharSet] componentsJoinedByString: @""]; - return cleanedString; }