From d18deb1faa5bc7a6177fb14e1f17c60a68412f28 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Tue, 2 Apr 2002 21:12:51 +0000 Subject: [PATCH] Bug 126669, we need to pass in aHasChildren parameter to the start tag serializing function because the node that is passed in may be a shallow copy, thereby making it impossible to determine if it originally had children, in the method itself. This fixes case where saving XHTML produces non-wellformed output. r=akkana,tmutreja, sr=jst, a=asa,ADT. git-svn-id: svn://10.0.0.236/trunk@117951 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIContentSerializer.h | 1 + mozilla/content/base/src/nsDocumentEncoder.cpp | 9 ++++++++- mozilla/content/base/src/nsHTMLContentSerializer.cpp | 1 + mozilla/content/base/src/nsHTMLContentSerializer.h | 1 + mozilla/content/base/src/nsPlainTextSerializer.cpp | 1 + mozilla/content/base/src/nsPlainTextSerializer.h | 1 + mozilla/content/base/src/nsXMLContentSerializer.cpp | 5 ++--- mozilla/content/base/src/nsXMLContentSerializer.h | 1 + 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mozilla/content/base/public/nsIContentSerializer.h b/mozilla/content/base/public/nsIContentSerializer.h index 964e12a280f..2376e917a42 100644 --- a/mozilla/content/base/public/nsIContentSerializer.h +++ b/mozilla/content/base/public/nsIContentSerializer.h @@ -84,6 +84,7 @@ class nsIContentSerializer : public nsISupports { nsAString& aStr) = 0; NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr) = 0; NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, diff --git a/mozilla/content/base/src/nsDocumentEncoder.cpp b/mozilla/content/base/src/nsDocumentEncoder.cpp index d4b2c6a6f68..42d43e9ad65 100644 --- a/mozilla/content/base/src/nsDocumentEncoder.cpp +++ b/mozilla/content/base/src/nsDocumentEncoder.cpp @@ -308,7 +308,14 @@ nsDocumentEncoder::SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset, case nsIDOMNode::ELEMENT_NODE: { nsCOMPtr element = do_QueryInterface(node); - mSerializer->AppendElementStart(element, aStr); + // Because FixupNode() may have done a shallow copy of aNode + // we need to tell the serializer if the original had children. + // Some serializers (notably XML) need this information + // in order to handle empty tags properly. + PRBool hasChildren; + mSerializer->AppendElementStart(element, + NS_SUCCEEDED(aNode->HasChildNodes(&hasChildren)) && hasChildren, + aStr); break; } case nsIDOMNode::TEXT_NODE: diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.cpp b/mozilla/content/base/src/nsHTMLContentSerializer.cpp index bafe84d92ad..e1ed60f5752 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsHTMLContentSerializer.cpp @@ -411,6 +411,7 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent, NS_IMETHODIMP nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr) { NS_ENSURE_ARG(aElement); diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.h b/mozilla/content/base/src/nsHTMLContentSerializer.h index 7b04a909cfb..81bf8db8a82 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.h +++ b/mozilla/content/base/src/nsHTMLContentSerializer.h @@ -59,6 +59,7 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer { PRInt32 aEndOffset, nsAString& aStr); NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr); NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index 6c1682a587d..25b16ee5016 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -319,6 +319,7 @@ nsPlainTextSerializer::AppendText(nsIDOMText* aText, NS_IMETHODIMP nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr) { NS_ENSURE_ARG(aElement); diff --git a/mozilla/content/base/src/nsPlainTextSerializer.h b/mozilla/content/base/src/nsPlainTextSerializer.h index 1e44d642c75..73211f30efb 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.h +++ b/mozilla/content/base/src/nsPlainTextSerializer.h @@ -80,6 +80,7 @@ public: NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString& aStr) { return NS_OK; } NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr); NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, nsAString& aStr); diff --git a/mozilla/content/base/src/nsXMLContentSerializer.cpp b/mozilla/content/base/src/nsXMLContentSerializer.cpp index 7e3e276c84b..a3c08442d8b 100644 --- a/mozilla/content/base/src/nsXMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsXMLContentSerializer.cpp @@ -406,6 +406,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix, NS_IMETHODIMP nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr) { NS_ENSURE_ARG(aElement); @@ -509,9 +510,7 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, } // We don't output a separate end tag for empty element - nsCOMPtr node(do_QueryInterface(aElement)); - PRBool hasChildren; - if (NS_SUCCEEDED(node->HasChildNodes(&hasChildren)) && !hasChildren) { + if (!aHasChildren) { AppendToString(NS_LITERAL_STRING("/>"), aStr); } else { AppendToString(NS_LITERAL_STRING(">"), aStr); diff --git a/mozilla/content/base/src/nsXMLContentSerializer.h b/mozilla/content/base/src/nsXMLContentSerializer.h index f314ed2818c..06845562d9a 100644 --- a/mozilla/content/base/src/nsXMLContentSerializer.h +++ b/mozilla/content/base/src/nsXMLContentSerializer.h @@ -75,6 +75,7 @@ class nsXMLContentSerializer : public nsIContentSerializer { nsAString& aStr); NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, + PRBool aHasChildren, nsAString& aStr); NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,