fix(mail): ensure </html> is at the end of the document prior parsing

Fixes #5477
This commit is contained in:
Francis Lachapelle
2022-02-07 15:00:22 -05:00
parent a1d74a8910
commit a09cf58915
+19 -1
View File
@@ -250,7 +250,7 @@
const char *bytes;
char *buf;
int i, j, len;
BOOL found_delimiter, in_meta;
BOOL found_delimiter, in_meta, delete_html_end_tag;
d = [NSMutableData dataWithData: self];
bytes = [d bytes];
@@ -258,6 +258,7 @@
i = 0;
in_meta = NO;
delete_html_end_tag = NO;
while (i < len)
{
@@ -388,6 +389,20 @@
}
tag = [tags nextObject];
}
if ([@"html" caseInsensitiveCompare: found_tag] == NSOrderedSame)
{
// Remove </html>
delete_html_end_tag = YES;
i -= 2;
[d replaceBytesInRange: NSMakeRange(i, 7)
withBytes: NULL
length: 0];
bytes = [d bytes];
bytes += i;
len = [d length];
}
free(buf);
// Continue the parsing after end tag
@@ -401,6 +416,9 @@
i++;
}
if (delete_html_end_tag)
[d appendBytes: "</html>" length: 7];
return d;
}