From 0db543897be836d32b52aa626b2695469aa9a725 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Mon, 19 Jul 1999 05:30:49 +0000 Subject: [PATCH] fix bug 10109 git-svn-id: svn://10.0.0.236/trunk@40077 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/nsHTMLTokenizer.cpp | 1 + mozilla/htmlparser/src/nsScanner.cpp | 24 ++++++------------- .../parser/htmlparser/src/nsHTMLTokenizer.cpp | 1 + mozilla/parser/htmlparser/src/nsScanner.cpp | 24 ++++++------------- 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp index 1dafa71457a..2968a0195b5 100644 --- a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp @@ -551,6 +551,7 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne //convert it into a text token. nsAutoString temp("&"); temp.Append(theStr); + temp.Append(';'); CToken* theToken=theRecycler->CreateTokenOfType(eToken_text,eHTMLTag_text,temp); theRecycler->RecycleToken(aToken); aToken=theToken; diff --git a/mozilla/htmlparser/src/nsScanner.cpp b/mozilla/htmlparser/src/nsScanner.cpp index b4af436933c..f1a2033b1fa 100644 --- a/mozilla/htmlparser/src/nsScanner.cpp +++ b/mozilla/htmlparser/src/nsScanner.cpp @@ -243,27 +243,17 @@ PRBool nsScanner::Append(nsString& aBuffer) { */ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ - /*************************** SUBTLETY ALERT!! ************************ - The following block of code converts aBuffer into unicode. - The subtlty is that we do it "in-place" on the underlying mBuffer. - This is so that we can avoid unnecessary copying of buffer data. - *********************************************************************/ - if(mUnicodeDecoder) { PRInt32 unicharBufLen = 0; - mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); - mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen); - PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode(); - unichars+=mBuffer.mLength; + mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); + PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; nsresult res; do { PRInt32 srcLength = aLen; PRInt32 unicharLength = unicharBufLen; res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength ); - unichars[mBuffer.mLength+unicharLength]=0; //add this since the unicode converters can't be trusted to do so. - mBuffer.mLength+=unicharLength; - // mBuffer.Append(unichars, unicharLength); - + unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so. + mBuffer.Append(unichars, unicharLength); mTotalRead += unicharLength; // if we failed, we consume one byte by replace it with U+FFFD // and try conversion again. @@ -277,14 +267,14 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ srcLength++; aBuffer += srcLength; aLen -= srcLength; - } //if + } } while (NS_FAILED(res) && (aLen > 0)); // we continue convert the bytes data into Unicode // if we have conversion error and we have more data. - //delete[] unichars; + delete[] unichars; } - else { + else { mBuffer.Append(aBuffer,aLen); mTotalRead+=aLen; } diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp index 1dafa71457a..2968a0195b5 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp @@ -551,6 +551,7 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne //convert it into a text token. nsAutoString temp("&"); temp.Append(theStr); + temp.Append(';'); CToken* theToken=theRecycler->CreateTokenOfType(eToken_text,eHTMLTag_text,temp); theRecycler->RecycleToken(aToken); aToken=theToken; diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp index b4af436933c..f1a2033b1fa 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.cpp +++ b/mozilla/parser/htmlparser/src/nsScanner.cpp @@ -243,27 +243,17 @@ PRBool nsScanner::Append(nsString& aBuffer) { */ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ - /*************************** SUBTLETY ALERT!! ************************ - The following block of code converts aBuffer into unicode. - The subtlty is that we do it "in-place" on the underlying mBuffer. - This is so that we can avoid unnecessary copying of buffer data. - *********************************************************************/ - if(mUnicodeDecoder) { PRInt32 unicharBufLen = 0; - mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); - mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen); - PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode(); - unichars+=mBuffer.mLength; + mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); + PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; nsresult res; do { PRInt32 srcLength = aLen; PRInt32 unicharLength = unicharBufLen; res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength ); - unichars[mBuffer.mLength+unicharLength]=0; //add this since the unicode converters can't be trusted to do so. - mBuffer.mLength+=unicharLength; - // mBuffer.Append(unichars, unicharLength); - + unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so. + mBuffer.Append(unichars, unicharLength); mTotalRead += unicharLength; // if we failed, we consume one byte by replace it with U+FFFD // and try conversion again. @@ -277,14 +267,14 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ srcLength++; aBuffer += srcLength; aLen -= srcLength; - } //if + } } while (NS_FAILED(res) && (aLen > 0)); // we continue convert the bytes data into Unicode // if we have conversion error and we have more data. - //delete[] unichars; + delete[] unichars; } - else { + else { mBuffer.Append(aBuffer,aLen); mTotalRead+=aLen; }