From 4cb9ed22c69daed8709bb86a2afc5efe8d927133 Mon Sep 17 00:00:00 2001 From: "nisheeth%netscape.com" Date: Thu, 8 Apr 1999 09:21:16 +0000 Subject: [PATCH] - Enable expat by default. If you run into problems, you can disable expat at run-time by setting NOEXPAT=1 in your environment on Windows and UNIX. On Mac, create a file called NOEXPAT in the directory from which you run the browser. - Changed nsExpatTokenizer so that it stops parsing buffers once it sees an XML well-formedness error. git-svn-id: svn://10.0.0.236/trunk@26804 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/nsExpatTokenizer.cpp | 18 ++++++++++++------ mozilla/htmlparser/src/nsExpatTokenizer.h | 1 + mozilla/htmlparser/src/nsWellFormedDTD.cpp | 8 ++++---- .../parser/htmlparser/src/nsExpatTokenizer.cpp | 18 ++++++++++++------ .../parser/htmlparser/src/nsExpatTokenizer.h | 1 + .../parser/htmlparser/src/nsWellFormedDTD.cpp | 8 ++++---- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/mozilla/htmlparser/src/nsExpatTokenizer.cpp b/mozilla/htmlparser/src/nsExpatTokenizer.cpp index e9923130a65..5fad29e7e20 100644 --- a/mozilla/htmlparser/src/nsExpatTokenizer.cpp +++ b/mozilla/htmlparser/src/nsExpatTokenizer.cpp @@ -133,6 +133,7 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) { nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() { NS_INIT_REFCNT(); mBytesParsed = 0; + mSeenError = PR_FALSE; mExpatParser = XML_ParserCreate(NULL); gTokenRecycler=(CTokenRecycler*)GetTokenRecycler(); if (mExpatParser) { @@ -148,8 +149,10 @@ nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() { * @return */ nsExpatTokenizer::~nsExpatTokenizer(){ - if (mExpatParser) - XML_ParserFree(mExpatParser); + if (mExpatParser) { + XML_ParserFree(mExpatParser); + mExpatParser = nsnull; + } } @@ -232,10 +235,13 @@ nsresult nsExpatTokenizer::ParseXMLBuffer(const char *aBuffer, PRUint32 aLength) nsresult result=NS_OK; if (mExpatParser) { PR_ASSERT(aLength == strlen(aBuffer)); - if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) { - PushXMLErrorToken(aBuffer, aLength); - } - mBytesParsed += aLength; + if (!mSeenError) { + if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) { + PushXMLErrorToken(aBuffer, aLength); + mSeenError = PR_TRUE; + } + mBytesParsed += aLength; + } } else { result = NS_ERROR_FAILURE; diff --git a/mozilla/htmlparser/src/nsExpatTokenizer.h b/mozilla/htmlparser/src/nsExpatTokenizer.h index 386e7899a21..9c79b0e3d56 100644 --- a/mozilla/htmlparser/src/nsExpatTokenizer.h +++ b/mozilla/htmlparser/src/nsExpatTokenizer.h @@ -107,6 +107,7 @@ protected: XML_Parser mExpatParser; PRUint32 mBytesParsed; + PRBool mSeenError; }; extern NS_HTMLPARS nsresult NS_Expat_Tokenizer(nsIDTD** aInstancePtrResult); diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/htmlparser/src/nsWellFormedDTD.cpp index df174fb96c3..1833f7eb426 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/htmlparser/src/nsWellFormedDTD.cpp @@ -330,18 +330,18 @@ nsITokenRecycler* CWellFormedDTD::GetTokenRecycler(void){ */ nsITokenizer* CWellFormedDTD::GetTokenizer(void) { if(!mTokenizer) { - PRBool theExpatState=PR_FALSE; + PRBool theExpatState=PR_TRUE; #ifndef XP_MAC - char* theEnvString = PR_GetEnv("EXPAT"); + char* theEnvString = PR_GetEnv("NOEXPAT"); if(theEnvString){ if(('1'==theEnvString[0]) || ('Y'==theEnvString[0]) || ('y'==theEnvString[0])) { - theExpatState=PR_TRUE; //this indicates that the EXPAT flag was found in the environment. + theExpatState=PR_FALSE; //this indicates that the EXPAT flag was found in the environment. } } #else // Check for the existence of a file called EXPAT in the current directory nsSpecialSystemDirectory expatFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - expatFile += "EXPAT"; + expatFile += "NOEXPAT"; theExpatState = expatFile.Exists(); #endif if(theExpatState) { diff --git a/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp b/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp index e9923130a65..5fad29e7e20 100644 --- a/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp @@ -133,6 +133,7 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) { nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() { NS_INIT_REFCNT(); mBytesParsed = 0; + mSeenError = PR_FALSE; mExpatParser = XML_ParserCreate(NULL); gTokenRecycler=(CTokenRecycler*)GetTokenRecycler(); if (mExpatParser) { @@ -148,8 +149,10 @@ nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() { * @return */ nsExpatTokenizer::~nsExpatTokenizer(){ - if (mExpatParser) - XML_ParserFree(mExpatParser); + if (mExpatParser) { + XML_ParserFree(mExpatParser); + mExpatParser = nsnull; + } } @@ -232,10 +235,13 @@ nsresult nsExpatTokenizer::ParseXMLBuffer(const char *aBuffer, PRUint32 aLength) nsresult result=NS_OK; if (mExpatParser) { PR_ASSERT(aLength == strlen(aBuffer)); - if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) { - PushXMLErrorToken(aBuffer, aLength); - } - mBytesParsed += aLength; + if (!mSeenError) { + if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) { + PushXMLErrorToken(aBuffer, aLength); + mSeenError = PR_TRUE; + } + mBytesParsed += aLength; + } } else { result = NS_ERROR_FAILURE; diff --git a/mozilla/parser/htmlparser/src/nsExpatTokenizer.h b/mozilla/parser/htmlparser/src/nsExpatTokenizer.h index 386e7899a21..9c79b0e3d56 100644 --- a/mozilla/parser/htmlparser/src/nsExpatTokenizer.h +++ b/mozilla/parser/htmlparser/src/nsExpatTokenizer.h @@ -107,6 +107,7 @@ protected: XML_Parser mExpatParser; PRUint32 mBytesParsed; + PRBool mSeenError; }; extern NS_HTMLPARS nsresult NS_Expat_Tokenizer(nsIDTD** aInstancePtrResult); diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp index df174fb96c3..1833f7eb426 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -330,18 +330,18 @@ nsITokenRecycler* CWellFormedDTD::GetTokenRecycler(void){ */ nsITokenizer* CWellFormedDTD::GetTokenizer(void) { if(!mTokenizer) { - PRBool theExpatState=PR_FALSE; + PRBool theExpatState=PR_TRUE; #ifndef XP_MAC - char* theEnvString = PR_GetEnv("EXPAT"); + char* theEnvString = PR_GetEnv("NOEXPAT"); if(theEnvString){ if(('1'==theEnvString[0]) || ('Y'==theEnvString[0]) || ('y'==theEnvString[0])) { - theExpatState=PR_TRUE; //this indicates that the EXPAT flag was found in the environment. + theExpatState=PR_FALSE; //this indicates that the EXPAT flag was found in the environment. } } #else // Check for the existence of a file called EXPAT in the current directory nsSpecialSystemDirectory expatFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - expatFile += "EXPAT"; + expatFile += "NOEXPAT"; theExpatState = expatFile.Exists(); #endif if(theExpatState) {