(fix) rewrote the string sanitization to be 32-bit Unicode safe

pull/188/head
Ludovic Marcotte 2016-01-22 20:30:40 -05:00
parent 81f13404bf
commit 3c0059192d
2 changed files with 13 additions and 11 deletions

1
NEWS
View File

@ -6,6 +6,7 @@ New features
Buf fixes
- now always generate invitation updates when using EAS
- rewrote the string sanitization to be 32-bit Unicode safe
2.3.6 (2016-01-18)
------------------

View File

@ -291,34 +291,35 @@ static int cssEscapingCount;
//
- (NSString *) safeString
{
NSData *data;
NSString *s;
unichar *buf, *start, c;
const wchar_t *buf;
wchar_t *start, c;
int len, i, j;
len = [self length];
start = buf = (unichar *)malloc(len*sizeof(unichar));
[self getCharacters: buf range: NSMakeRange(0, len)];
data = [self dataUsingEncoding: NSUTF32LittleEndianStringEncoding];
len = [data length];
buf = [data bytes];
start = (wchar_t *)calloc(len, sizeof(wchar_t));
for (i = 0, j = 0; i < len; i++)
for (i = 0, j = 0; i < len/4; i++)
{
c = *buf;
c = buf[i];
if (c == 0x9 ||
c == 0xA ||
c == 0xD ||
(c >= 0x20 && c <= 0xD7FF) ||
(c >= 0xE000 && c <= 0xFFFD) ||
(c >= (unichar)0x10000 && c <= (unichar)0x10FFFF))
(c >= (wchar_t)0x10000 && c <= (wchar_t)0x10FFFF))
{
*(start+j) = c;
start[j] = c;
j++;
}
buf++;
}
s = [[NSString alloc] initWithCharactersNoCopy: start length: j freeWhenDone: YES];
s = [[NSString alloc] initWithBytesNoCopy: start length: j*sizeof(wchar_t) encoding: NSUTF32LittleEndianStringEncoding freeWhenDone: YES];
return AUTORELEASE(s);
}