Fixed charset substitution in meta tags

pull/47/head
Ludovic Marcotte 2014-07-21 15:34:56 -04:00
parent 11920f592c
commit 08cd080d47
2 changed files with 20 additions and 17 deletions

1
NEWS
View File

@ -11,6 +11,7 @@ Bug fixes
- fixed rename of calendars - fixed rename of calendars
- we now correctly add the "METHOD:REPLY" when sending out ITIP messages from DAV clients - we now correctly add the "METHOD:REPLY" when sending out ITIP messages from DAV clients
- fixed refresh of message headers when forwarding a message (#2818) - fixed refresh of message headers when forwarding a message (#2818)
- we now correctly escape all charset= in <meta> tags, not only in the <head>
2.2.6 (2014-07-02) 2.2.6 (2014-07-02)
------------------ ------------------

View File

@ -146,34 +146,34 @@ static NSData* _sanitizeContent(NSData *theData)
const char *bytes; const char *bytes;
char *buf; char *buf;
int i, j, len; int i, j, len;
BOOL found_delimiter; BOOL found_delimiter, in_meta;
d = [NSMutableData dataWithData: theData]; d = [NSMutableData dataWithData: theData];
bytes = [d bytes]; bytes = [d bytes];
len = [d length]; len = [d length];
i = 0; i = 0;
in_meta = NO;
while (i < len) while (i < len)
{ {
// We check if we see </head> in which case, we don't do any kind // We check if we see <meta ...> in which case, we substitute de charset= stuff.
// of substitution there after. if (i < len-5)
if (i < len-6)
{ {
if ((*bytes == '<') && if ((*bytes == '<') &&
(*(bytes+1) == '/') && (*(bytes+1) == 'm' || *(bytes+2) == 'M') &&
(*(bytes+2) == 'h' || *(bytes+2) == 'H') && (*(bytes+2) == 'e' || *(bytes+3) == 'E') &&
(*(bytes+3) == 'e' || *(bytes+3) == 'E') && (*(bytes+3) == 't' || *(bytes+4) == 'T') &&
(*(bytes+4) == 'a' || *(bytes+4) == 'A') && (*(bytes+4) == 'a' || *(bytes+5) == 'A') &&
(*(bytes+5) == 'd' || *(bytes+5) == 'D') && (*(bytes+5) == ' '))
(*(bytes+6) == '>')) in_meta = YES;
break;
} }
// We search for something like : // We search for something like :
// //
// <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"> // <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
// //
if (i < len-9) if (in_meta && i < len-9)
{ {
if ((*bytes == 'c' || *bytes == 'C') && if ((*bytes == 'c' || *bytes == 'C') &&
(*(bytes+1) == 'h' || *(bytes+1) == 'H') && (*(bytes+1) == 'h' || *(bytes+1) == 'H') &&
@ -195,16 +195,18 @@ static NSData* _sanitizeContent(NSData *theData)
// We haven't found anything, let's return the data untouched // We haven't found anything, let's return the data untouched
if ((i+j) >= len) if ((i+j) >= len)
{ {
found_delimiter = NO; in_meta = found_delimiter = NO;
break; break;
} }
} }
if (found_delimiter) if (found_delimiter)
[d replaceBytesInRange: NSMakeRange(i, j) {
withBytes: NULL [d replaceBytesInRange: NSMakeRange(i, j)
length: 0]; withBytes: NULL
break; length: 0];
in_meta = found_delimiter = NO;
}
} }
} }