From 772c73ac13373fc726879674335ca75f2c2bb9f5 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 7 Sep 2012 16:44:13 +0000 Subject: [PATCH] Monotone-Parent: 053b5d33cbcf453e7c7216c0b2a168a0f0ffa0d5 Monotone-Revision: 7c8fce0426b2ec4def5226f16a9bcf2cff5dcfb9 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-09-07T16:44:13 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 +++++ OpenChange/NSString+MAPIStore.m | 45 ++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a2b719ce..180490185 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-07 Wolfgang Sourdeau + + * OpenChange/NSString+MAPIStore.m + (-stringByReplacingPercentEscapesUsingEncoding:): we now return + nil for non-ascii strings. + 2012-09-06 Wolfgang Sourdeau * OpenChange/NSString+MAPIStore.m diff --git a/OpenChange/NSString+MAPIStore.m b/OpenChange/NSString+MAPIStore.m index c8e31866e..83ca8d6e6 100644 --- a/OpenChange/NSString+MAPIStore.m +++ b/OpenChange/NSString+MAPIStore.m @@ -161,34 +161,39 @@ char newByte0, newByte1; data = [self dataUsingEncoding: NSASCIIStringEncoding]; - length = [data length]; - bytes = [data bytes]; - newBytes = NSZoneMalloc (NULL, sizeof (char) * length); - newCount = 0; - for (count = 0; count < length; count++) + if (data) { - if (bytes[count] == '%') + length = [data length]; + bytes = [data bytes]; + newBytes = NSZoneMalloc (NULL, sizeof (char) * length); + newCount = 0; + for (count = 0; count < length; count++) { - newByte0 = [self _decodeHexByte: bytes[count+1]]; - newByte1 = [self _decodeHexByte: bytes[count+2]]; - if ((newByte0 != -1) && (newByte1 != -1)) + if (bytes[count] == '%') { - newBytes[newCount] = (((newByte0 << 4) & 0xf0) - | (newByte1 & 0x0f)); - count += 2; + newByte0 = [self _decodeHexByte: bytes[count+1]]; + newByte1 = [self _decodeHexByte: bytes[count+2]]; + if ((newByte0 != -1) && (newByte1 != -1)) + { + newBytes[newCount] = (((newByte0 << 4) & 0xf0) + | (newByte1 & 0x0f)); + count += 2; + } + else + newBytes[newCount] = bytes[count]; } else newBytes[newCount] = bytes[count]; + newCount++; } - else - newBytes[newCount] = bytes[count]; - newCount++; - } - data = [NSData dataWithBytesNoCopy: newBytes length: newCount freeWhenDone: YES]; - newString = [[NSString alloc] - initWithData: data encoding: encoding]; - [newString autorelease]; + data = [NSData dataWithBytesNoCopy: newBytes length: newCount freeWhenDone: YES]; + newString = [[NSString alloc] + initWithData: data encoding: encoding]; + [newString autorelease]; + } + else + newString = nil; return newString; }