From d35e12a6210b89eda136d55e488c4ee324fbf41e Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 16 Oct 2001 01:31:49 +0000 Subject: [PATCH] Fixing bug 104031. Bad string code in nsHTMLDocument::WriteCommon(). r=bzbarsky@mit.edu, sr=vidur@netscape.com --- content/html/document/src/nsHTMLDocument.cpp | 18 ++++++------------ htmlparser/public/nsIParser.h | 2 +- htmlparser/src/CParserContext.cpp | 2 +- htmlparser/src/CParserContext.h | 2 +- htmlparser/src/nsParser.cpp | 8 +++++--- htmlparser/src/nsParser.h | 2 +- parser/htmlparser/public/nsIParser.h | 2 +- parser/htmlparser/src/CParserContext.cpp | 2 +- parser/htmlparser/src/CParserContext.h | 2 +- parser/htmlparser/src/nsParser.cpp | 8 +++++--- parser/htmlparser/src/nsParser.h | 2 +- 11 files changed, 24 insertions(+), 26 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 893b3e2264b..68d332b76e8 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2296,19 +2296,13 @@ nsHTMLDocument::WriteCommon(const nsAReadableString& aText, } } - const nsAReadableString *text_to_write = &aText; - nsAutoString string_buffer; - - if (aNewlineTerminate) { - string_buffer.Assign(aText); - string_buffer.Append((PRUnichar)'\n'); - - text_to_write = &string_buffer; - } - mWriteLevel++; - rv = mParser->Parse(*text_to_write, NS_GENERATE_PARSER_KEY(), - NS_ConvertASCIItoUCS2("text/html"), PR_FALSE, + + static const NS_NAMED_LITERAL_STRING(sNewLine, "\n"); + + rv = mParser->Parse(aNewlineTerminate ? (aText + sNewLine) : aText, + NS_GENERATE_PARSER_KEY(), + NS_LITERAL_STRING("text/html"), PR_FALSE, (!mIsWriting || (mWriteLevel > 1))); mWriteLevel--; diff --git a/htmlparser/public/nsIParser.h b/htmlparser/public/nsIParser.h index 3e6ad765571..b7d83795f6b 100644 --- a/htmlparser/public/nsIParser.h +++ b/htmlparser/public/nsIParser.h @@ -247,7 +247,7 @@ class nsIParser : public nsISupports { virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; virtual nsresult Parse(nsIInputStream& aStream, const nsString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; + virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; virtual nsresult Terminate(void) = 0; diff --git a/htmlparser/src/CParserContext.cpp b/htmlparser/src/CParserContext.cpp index a73eef35625..040cb06db77 100644 --- a/htmlparser/src/CParserContext.cpp +++ b/htmlparser/src/CParserContext.cpp @@ -143,7 +143,7 @@ CParserContext::~CParserContext(){ * Set's the mimetype for this context * @update rickg 03.18.2000 */ -void CParserContext::SetMimeType(const nsString& aMimeType){ +void CParserContext::SetMimeType(nsAReadableString& aMimeType){ mMimeType.Assign(aMimeType); mDocType=ePlainText; diff --git a/htmlparser/src/CParserContext.h b/htmlparser/src/CParserContext.h index e128e8a13fb..c0f2e51a320 100644 --- a/htmlparser/src/CParserContext.h +++ b/htmlparser/src/CParserContext.h @@ -76,7 +76,7 @@ public: CParserContext( const CParserContext& aContext); ~CParserContext(); - void SetMimeType(const nsString& aMimeType); + void SetMimeType(nsAReadableString& aMimeType); CParserContext* mPrevContext; nsDTDMode mDTDMode; diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index 99d4a1a5c65..54b3c53eb72 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -1676,9 +1676,11 @@ nsresult nsParser::Parse(nsIInputStream& aStream,const nsString& aMimeType,PRBoo * @param aMimeType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& -aMimeType,PRBool aVerifyEnabled,PRBool aLastCall,nsDTDMode aMode){ - +nsresult nsParser::Parse(const nsAReadableString& aSourceBuffer, void* aKey, + const nsAReadableString& aMimeType, + PRBool aVerifyEnabled, PRBool aLastCall, + nsDTDMode aMode){ + //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! diff --git a/htmlparser/src/nsParser.h b/htmlparser/src/nsParser.h index c0612e652b9..e0b32c077fd 100644 --- a/htmlparser/src/nsParser.h +++ b/htmlparser/src/nsParser.h @@ -213,7 +213,7 @@ class nsParser : public nsIParser, * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); + virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); virtual nsresult ParseFragment(const nsAReadableString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType,nsDTDMode aMode=eDTDMode_autodetect); diff --git a/parser/htmlparser/public/nsIParser.h b/parser/htmlparser/public/nsIParser.h index 3e6ad765571..b7d83795f6b 100644 --- a/parser/htmlparser/public/nsIParser.h +++ b/parser/htmlparser/public/nsIParser.h @@ -247,7 +247,7 @@ class nsIParser : public nsISupports { virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; virtual nsresult Parse(nsIInputStream& aStream, const nsString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; + virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; virtual nsresult Terminate(void) = 0; diff --git a/parser/htmlparser/src/CParserContext.cpp b/parser/htmlparser/src/CParserContext.cpp index a73eef35625..040cb06db77 100644 --- a/parser/htmlparser/src/CParserContext.cpp +++ b/parser/htmlparser/src/CParserContext.cpp @@ -143,7 +143,7 @@ CParserContext::~CParserContext(){ * Set's the mimetype for this context * @update rickg 03.18.2000 */ -void CParserContext::SetMimeType(const nsString& aMimeType){ +void CParserContext::SetMimeType(nsAReadableString& aMimeType){ mMimeType.Assign(aMimeType); mDocType=ePlainText; diff --git a/parser/htmlparser/src/CParserContext.h b/parser/htmlparser/src/CParserContext.h index e128e8a13fb..c0f2e51a320 100644 --- a/parser/htmlparser/src/CParserContext.h +++ b/parser/htmlparser/src/CParserContext.h @@ -76,7 +76,7 @@ public: CParserContext( const CParserContext& aContext); ~CParserContext(); - void SetMimeType(const nsString& aMimeType); + void SetMimeType(nsAReadableString& aMimeType); CParserContext* mPrevContext; nsDTDMode mDTDMode; diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 99d4a1a5c65..54b3c53eb72 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -1676,9 +1676,11 @@ nsresult nsParser::Parse(nsIInputStream& aStream,const nsString& aMimeType,PRBoo * @param aMimeType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& -aMimeType,PRBool aVerifyEnabled,PRBool aLastCall,nsDTDMode aMode){ - +nsresult nsParser::Parse(const nsAReadableString& aSourceBuffer, void* aKey, + const nsAReadableString& aMimeType, + PRBool aVerifyEnabled, PRBool aLastCall, + nsDTDMode aMode){ + //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! diff --git a/parser/htmlparser/src/nsParser.h b/parser/htmlparser/src/nsParser.h index c0612e652b9..e0b32c077fd 100644 --- a/parser/htmlparser/src/nsParser.h +++ b/parser/htmlparser/src/nsParser.h @@ -213,7 +213,7 @@ class nsParser : public nsIParser, * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); + virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); virtual nsresult ParseFragment(const nsAReadableString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType,nsDTDMode aMode=eDTDMode_autodetect);