Bug 245399: HTML-escape ' (single quote), too

This commit is contained in:
mozilla.BenB%bucksch.org 2004-06-05 22:26:46 +00:00
parent 00d323cc89
commit c9b08c0bc9

View File

@ -205,7 +205,8 @@ NS_COM PRInt32 nsUnescapeCount(char * str)
NS_COM char *
nsEscapeHTML(const char * string)
{
char *rv = (char *) nsMemory::Alloc(strlen(string)*6 + 1); /* The +1 is for the trailing null! */
// hardcoded max entity len
char *rv = (char *) nsMemory::Alloc(strlen(string)*7 + 1); /* The +1 is for the trailing null! */
char *ptr = rv;
if(rv)
@ -243,6 +244,16 @@ nsEscapeHTML(const char * string)
*ptr++ = 't';
*ptr++ = ';';
}
else if (*string == '\'')
{
*ptr++ = '&';
*ptr++ = 'l';
*ptr++ = 's';
*ptr++ = 'q';
*ptr++ = 'u';
*ptr++ = 'o';
*ptr++ = ';';
}
else
{
*ptr++ = *string;
@ -262,7 +273,8 @@ nsEscapeHTML2(const PRUnichar *aSourceBuffer, PRInt32 aSourceBufferLen)
aSourceBufferLen = nsCRT::strlen(aSourceBuffer); // ...then I will
}
PRUnichar *resultBuffer = (PRUnichar *)nsMemory::Alloc(aSourceBufferLen*6*sizeof(PRUnichar) + sizeof(PRUnichar('\0')));
// hardcoded max entity len
PRUnichar *resultBuffer = (PRUnichar *)nsMemory::Alloc(aSourceBufferLen*7*sizeof(PRUnichar) + sizeof(PRUnichar('\0')));
PRUnichar *ptr = resultBuffer;
if (resultBuffer) {
@ -292,6 +304,14 @@ nsEscapeHTML2(const PRUnichar *aSourceBuffer, PRInt32 aSourceBufferLen)
*ptr++ = 'o';
*ptr++ = 't';
*ptr++ = ';';
} else if (aSourceBuffer[i] == '\'') {
*ptr++ = '&';
*ptr++ = 'l';
*ptr++ = 's';
*ptr++ = 'q';
*ptr++ = 'u';
*ptr++ = 'o';
*ptr++ = ';';
} else {
*ptr++ = aSourceBuffer[i];
}