From 913669048f523bcb2066bcb91fdd7d6dd84e42fb Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Fri, 7 Mar 2003 23:40:51 +0000 Subject: [PATCH] Bug 191327, make internalSubset not include delimiting brackets (was not defined in DOM 2 but is now defined in DOM 3 drafts). Also fix bug 191482, external entity definitions should be included in internal subset. r=harishd, jst, sr=peterv. git-svn-id: svn://10.0.0.236/trunk@139121 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/src/nsXMLContentSerializer.cpp | 5 +-- mozilla/expat/xmlparse/xmlparse.c | 2 +- mozilla/htmlparser/src/nsExpatDriver.cpp | 35 ++++++++++++++----- mozilla/parser/expat/lib/xmlparse.c | 2 +- .../parser/htmlparser/src/nsExpatDriver.cpp | 35 ++++++++++++++----- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/mozilla/content/base/src/nsXMLContentSerializer.cpp b/mozilla/content/base/src/nsXMLContentSerializer.cpp index 3f577a2ace8..0a3d04cd092 100644 --- a/mozilla/content/base/src/nsXMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsXMLContentSerializer.cpp @@ -281,11 +281,12 @@ nsXMLContentSerializer::AppendDoctype(nsIDOMDocumentType *aDoctype, } if (!internalSubset.IsEmpty()) { - AppendToString(PRUnichar(' '), aStr); + AppendToString(NS_LITERAL_STRING(" ["), aStr); AppendToString(internalSubset, aStr); + AppendToString(PRUnichar(']'), aStr); } - AppendToString(NS_LITERAL_STRING(">"), aStr); + AppendToString(PRUnichar('>'), aStr); return NS_OK; } diff --git a/mozilla/expat/xmlparse/xmlparse.c b/mozilla/expat/xmlparse/xmlparse.c index 2b67f150e53..b5b74c7a9f8 100644 --- a/mozilla/expat/xmlparse/xmlparse.c +++ b/mozilla/expat/xmlparse/xmlparse.c @@ -2713,7 +2713,7 @@ doProlog(XML_Parser parser, dtd.complete = 0; entity->open = 1; if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, + entity->name, /* Mozilla bug 191482 */ entity->base, entity->systemId, entity->publicId)) { diff --git a/mozilla/htmlparser/src/nsExpatDriver.cpp b/mozilla/htmlparser/src/nsExpatDriver.cpp index 67916bd6eae..afbb006f9b1 100644 --- a/mozilla/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/htmlparser/src/nsExpatDriver.cpp @@ -530,9 +530,9 @@ nsExpatDriver::HandleEndDoctypeDecl() // let the sink know any additional knowledge that we have about the document // (currently, from bug 124570, we only expect to pass additional agent sheets // needed to layout the XML vocabulary of the document) - nsIURI* data = nsnull; + nsCOMPtr data; if (mCatalogData && mCatalogData->mAgentSheet) { - NS_NewURI(&data, mCatalogData->mAgentSheet); + NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet); } nsAutoString name; @@ -548,15 +548,26 @@ nsExpatDriver::HandleEndDoctypeDecl() GetDocTypeToken(mDoctypeText, systemId, PR_TRUE); } - // The rest is the internal subset (minus whitespace) + // The rest is the internal subset with [] (minus whitespace) mDoctypeText.Trim(kWhitespace); + // Take out the brackets too, if any + if (mDoctypeText.Length() > 2) { + const nsAString& internalSubset = Substring(mDoctypeText, 1, + mDoctypeText.Length() - 2); + mInternalState = mSink->HandleDoctypeDecl(internalSubset, + name, + systemId, + publicId, + data); + } else { + // There's nothing but brackets, don't include them + mInternalState = mSink->HandleDoctypeDecl(nsString(),// !internalSubset + name, + systemId, + publicId, + data); + } - mInternalState = mSink->HandleDoctypeDecl(mDoctypeText, - name, - systemId, - publicId, - data); - NS_IF_RELEASE(data); } mDoctypeText.SetCapacity(0); @@ -570,6 +581,12 @@ nsExpatDriver::HandleExternalEntityRef(const PRUnichar *openEntityNames, const PRUnichar *systemId, const PRUnichar *publicId) { + if (mInDoctype && !mInExternalDTD && openEntityNames) { + mDoctypeText.Append(PRUnichar('%')); + mDoctypeText.Append(nsDependentString(openEntityNames)); + mDoctypeText.Append(PRUnichar(';')); + } + int result = 1; // Load the external entity into a buffer diff --git a/mozilla/parser/expat/lib/xmlparse.c b/mozilla/parser/expat/lib/xmlparse.c index 2b67f150e53..b5b74c7a9f8 100644 --- a/mozilla/parser/expat/lib/xmlparse.c +++ b/mozilla/parser/expat/lib/xmlparse.c @@ -2713,7 +2713,7 @@ doProlog(XML_Parser parser, dtd.complete = 0; entity->open = 1; if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, + entity->name, /* Mozilla bug 191482 */ entity->base, entity->systemId, entity->publicId)) { diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index 67916bd6eae..afbb006f9b1 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -530,9 +530,9 @@ nsExpatDriver::HandleEndDoctypeDecl() // let the sink know any additional knowledge that we have about the document // (currently, from bug 124570, we only expect to pass additional agent sheets // needed to layout the XML vocabulary of the document) - nsIURI* data = nsnull; + nsCOMPtr data; if (mCatalogData && mCatalogData->mAgentSheet) { - NS_NewURI(&data, mCatalogData->mAgentSheet); + NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet); } nsAutoString name; @@ -548,15 +548,26 @@ nsExpatDriver::HandleEndDoctypeDecl() GetDocTypeToken(mDoctypeText, systemId, PR_TRUE); } - // The rest is the internal subset (minus whitespace) + // The rest is the internal subset with [] (minus whitespace) mDoctypeText.Trim(kWhitespace); + // Take out the brackets too, if any + if (mDoctypeText.Length() > 2) { + const nsAString& internalSubset = Substring(mDoctypeText, 1, + mDoctypeText.Length() - 2); + mInternalState = mSink->HandleDoctypeDecl(internalSubset, + name, + systemId, + publicId, + data); + } else { + // There's nothing but brackets, don't include them + mInternalState = mSink->HandleDoctypeDecl(nsString(),// !internalSubset + name, + systemId, + publicId, + data); + } - mInternalState = mSink->HandleDoctypeDecl(mDoctypeText, - name, - systemId, - publicId, - data); - NS_IF_RELEASE(data); } mDoctypeText.SetCapacity(0); @@ -570,6 +581,12 @@ nsExpatDriver::HandleExternalEntityRef(const PRUnichar *openEntityNames, const PRUnichar *systemId, const PRUnichar *publicId) { + if (mInDoctype && !mInExternalDTD && openEntityNames) { + mDoctypeText.Append(PRUnichar('%')); + mDoctypeText.Append(nsDependentString(openEntityNames)); + mDoctypeText.Append(PRUnichar(';')); + } + int result = 1; // Load the external entity into a buffer