From f436b7022692092a55bd898651a49a7c9ff0ed22 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 1 Sep 2005 18:59:46 +0000 Subject: [PATCH] Make sure random parts of external DTDs don't sneak into the DOM. Bug 306353, r+sr=peterv --- parser/htmlparser/src/nsExpatDriver.cpp | 39 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/parser/htmlparser/src/nsExpatDriver.cpp b/parser/htmlparser/src/nsExpatDriver.cpp index edd3c4619084..c36d91f621c8 100644 --- a/parser/htmlparser/src/nsExpatDriver.cpp +++ b/parser/htmlparser/src/nsExpatDriver.cpp @@ -413,10 +413,15 @@ nsExpatDriver::HandleComment(const PRUnichar *aValue) { NS_ASSERTION(mSink, "content sink not found!"); + if (mInExternalDTD) { + // Ignore comments from external DTDs + return NS_OK; + } + if (mInInternalSubset) { - if (!mInExternalDTD) { - mInternalSubset.Append(aValue); - } + mInternalSubset.AppendLiteral(""); } else if (mSink) { mInternalState = mSink->HandleComment(aValue); @@ -431,9 +436,22 @@ nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget, { NS_ASSERTION(mSink, "content sink not found!"); - if (mSink && - mSink->HandleProcessingInstruction(aTarget, aData) == - NS_ERROR_HTMLPARSER_BLOCK) { + if (mInExternalDTD) { + // Ignore PIs in external DTDs for now. Eventually we want to + // pass them to the sink in a way that doesn't put them in the DOM + return NS_OK; + } + + if (mInInternalSubset) { + mInternalSubset.AppendLiteral(""); + } + else if (mSink && + mSink->HandleProcessingInstruction(aTarget, aData) == + NS_ERROR_HTMLPARSER_BLOCK) { mInternalState = NS_ERROR_HTMLPARSER_BLOCK; MOZ_XML_StopParser(mExpatParser, XML_TRUE); } @@ -455,10 +473,13 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue, { NS_ASSERTION(mSink, "content sink not found!"); + if (mInExternalDTD) { + // Ignore newlines in external DTDs + return NS_OK; + } + if (mInInternalSubset) { - if (!mInExternalDTD) { - mInternalSubset.Append(aValue, aLength); - } + mInternalSubset.Append(aValue, aLength); } else if (mSink) { static const PRUnichar newline[] = { '\n', '\0' };