Fix for bug 332239 (Saved xml content gives xml parsing error in this case). r/zr=bz.

This commit is contained in:
peterv%propagandism.org 2006-04-06 20:55:25 +00:00
Родитель 64c5f05794
Коммит 2cd741e602
11 изменённых файлов: 25 добавлений и 26 удалений

Просмотреть файл

@ -85,7 +85,7 @@ class nsIContentSerializer : public nsISupports {
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,

Просмотреть файл

@ -243,7 +243,7 @@ mozSanitizingHTMLSerializer::AppendText(nsIDOMText* aText,
NS_IMETHODIMP NS_IMETHODIMP
mozSanitizingHTMLSerializer::AppendElementStart(nsIDOMElement *aElement, mozSanitizingHTMLSerializer::AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);

Просмотреть файл

@ -91,7 +91,8 @@ public:
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString& aStr) NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString& aStr)
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, PRBool aHasChildren, NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
nsIDOMElement *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, nsAString& aStr); NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, nsAString& aStr);
NS_IMETHOD Flush(nsAString& aStr); NS_IMETHOD Flush(nsAString& aStr);

Просмотреть файл

@ -284,14 +284,8 @@ nsDocumentEncoder::SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset,
case nsIDOMNode::ELEMENT_NODE: case nsIDOMNode::ELEMENT_NODE:
{ {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node); nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
// Because FixupNode() may have done a shallow copy of aNode nsCOMPtr<nsIDOMElement> originalElement = do_QueryInterface(aNode);
// we need to tell the serializer if the original had children. mSerializer->AppendElementStart(element, originalElement, aStr);
// 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; break;
} }
case nsIDOMNode::TEXT_NODE: case nsIDOMNode::TEXT_NODE:

Просмотреть файл

@ -636,7 +636,7 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
@ -720,7 +720,7 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
if (mIsCopying && name == nsHTMLAtoms::li) { if (mIsCopying && name == nsHTMLAtoms::li) {
mIsFirstChildOfOL = IsFirstChildOfOL(aElement); mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement);
if (mIsFirstChildOfOL){ if (mIsFirstChildOfOL){
// If OL is parent of this LI, serialize attributes in different manner. // If OL is parent of this LI, serialize attributes in different manner.
SerializeLIValueAttribute(aElement, aStr); SerializeLIValueAttribute(aElement, aStr);

Просмотреть файл

@ -65,7 +65,7 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer {
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,

Просмотреть файл

@ -380,7 +380,7 @@ nsPlainTextSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection,
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement, nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);

Просмотреть файл

@ -85,7 +85,7 @@ public:
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype,
nsAString& aStr) { return NS_OK; } nsAString& aStr) { return NS_OK; }
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,
nsAString& aStr); nsAString& aStr);

Просмотреть файл

@ -576,7 +576,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
@ -629,12 +629,12 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
else { else {
// Default NS attribute does not have prefix (and the name is "xmlns") // Default NS attribute does not have prefix (and the name is "xmlns")
PushNameSpaceDecl(EmptyString(), uriStr, aElement); PushNameSpaceDecl(EmptyString(), uriStr, aOriginalElement);
} }
} }
else { else {
attrName->ToString(nameStr); attrName->ToString(nameStr);
PushNameSpaceDecl(nameStr, uriStr, aElement); PushNameSpaceDecl(nameStr, uriStr, aOriginalElement);
} }
} }
} }
@ -643,7 +643,8 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
MaybeAddNewline(aStr); MaybeAddNewline(aStr);
addNSAttr = ConfirmPrefix(tagPrefix, tagNamespaceURI, aElement, PR_FALSE); addNSAttr = ConfirmPrefix(tagPrefix, tagNamespaceURI, aOriginalElement,
PR_FALSE);
// Serialize the qualified name of the element // Serialize the qualified name of the element
AppendToString(NS_LITERAL_STRING("<"), aStr); AppendToString(NS_LITERAL_STRING("<"), aStr);
if (!tagPrefix.IsEmpty()) { if (!tagPrefix.IsEmpty()) {
@ -662,7 +663,7 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
// Serialize namespace decl // Serialize namespace decl
SerializeAttr(xmlnsStr, tagPrefix, tagNamespaceURI, aStr, PR_TRUE); SerializeAttr(xmlnsStr, tagPrefix, tagNamespaceURI, aStr, PR_TRUE);
} }
PushNameSpaceDecl(tagPrefix, tagNamespaceURI, aElement); PushNameSpaceDecl(tagPrefix, tagNamespaceURI, aOriginalElement);
} }
// Now serialize each of the attributes // Now serialize each of the attributes
@ -688,7 +689,7 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
addNSAttr = PR_FALSE; addNSAttr = PR_FALSE;
if (kNameSpaceID_XMLNS != namespaceID) { if (kNameSpaceID_XMLNS != namespaceID) {
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr); nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr);
addNSAttr = ConfirmPrefix(prefixStr, uriStr, aElement, PR_TRUE); addNSAttr = ConfirmPrefix(prefixStr, uriStr, aOriginalElement, PR_TRUE);
} }
content->GetAttr(namespaceID, attrName, valueStr); content->GetAttr(namespaceID, attrName, valueStr);
@ -714,12 +715,14 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
NS_ASSERTION(!prefixStr.IsEmpty(), NS_ASSERTION(!prefixStr.IsEmpty(),
"Namespaced attributes must have a prefix"); "Namespaced attributes must have a prefix");
SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, PR_TRUE); SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, PR_TRUE);
PushNameSpaceDecl(prefixStr, uriStr, aElement); PushNameSpaceDecl(prefixStr, uriStr, aOriginalElement);
} }
} }
// We don't output a separate end tag for empty element // We don't output a separate end tag for empty element
if (!aHasChildren) { PRBool hasChildren;
if (NS_FAILED(aOriginalElement->HasChildNodes(&hasChildren)) ||
!hasChildren) {
AppendToString(NS_LITERAL_STRING("/>"), aStr); AppendToString(NS_LITERAL_STRING("/>"), aStr);
MaybeFlagNewline(aElement); MaybeFlagNewline(aElement);
} else { } else {

Просмотреть файл

@ -81,7 +81,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren, nsIDOMElement *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,

Просмотреть файл

@ -627,7 +627,8 @@ nsXBLBinding::GenerateAnonymousContent()
if (value.IsEmpty()) { if (value.IsEmpty()) {
nsAutoString value2; nsAutoString value2;
content->GetAttr(namespaceID, name, value2); content->GetAttr(namespaceID, name, value2);
mBoundElement->SetAttr(namespaceID, name, value2, PR_FALSE); mBoundElement->SetAttr(namespaceID, name, attrName->GetPrefix(),
value2, PR_FALSE);
} }
} }