Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Oct 2007 18:31:32 +0000 (18:31 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Oct 2007 18:31:32 +0000 (18:31 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=15650
        XML attribute nodes are not importable

        Tests: fast/dom/import-attribute-node.html
               fast/dom/import-document-fragment.html

        * dom/Document.cpp:
        (WebCore::Document::importNode): Implemented for Attribute and DocumentFragment nodes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27052 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/dom/xhtml/level3/core/nodeisequalnode17-expected.txt
LayoutTests/fast/dom/import-attribute-node-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/import-attribute-node.html [new file with mode: 0644]
LayoutTests/fast/dom/import-document-fragment-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/import-document-fragment.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.cpp

index 7b2d704..8f61cc3 100644 (file)
@@ -1,3 +1,17 @@
+2007-10-25  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15650
+        XML attribute nodes are not importable
+
+        * fast/dom/import-attribute-node-expected.txt: Added.
+        * fast/dom/import-attribute-node.html: Added.
+        * fast/dom/import-document-fragment-expected.txt: Added.
+        * fast/dom/import-document-fragment.html: Added.
+
+        * dom/xhtml/level3/core/nodeisequalnode17-expected.txt: Now passes.
+
 2007-10-25  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
index 31efd18..06cdbee 100644 (file)
@@ -1,3 +1,2 @@
 Test   http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode17
-Status error
-Message        Error: NOT_SUPPORTED_ERR: DOM Exception 9
+Status Success
diff --git a/LayoutTests/fast/dom/import-attribute-node-expected.txt b/LayoutTests/fast/dom/import-attribute-node-expected.txt
new file mode 100644 (file)
index 0000000..ffa6907
--- /dev/null
@@ -0,0 +1,3 @@
+Test for bug 15650: XML attribute nodes are not importable.
+
+SUCCESS
diff --git a/LayoutTests/fast/dom/import-attribute-node.html b/LayoutTests/fast/dom/import-attribute-node.html
new file mode 100644 (file)
index 0000000..ed79b0c
--- /dev/null
@@ -0,0 +1,26 @@
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=15650">bug 15650</a>:
+XML attribute nodes are not importable.</p>
+<script>
+if (window.layoutTestController)
+  layoutTestController.dumpAsText();
+
+try {
+  var xmld = new DOMParser().parseFromString( "<foo test='baz'/>", "text/xml");
+  var xmld2 = new DOMParser().parseFromString("<bar/>", "text/xml");
+
+  var srcElem = xmld.documentElement;
+  var dstElem = xmld2.documentElement;
+
+  var importedNode = xmld2.importNode(srcElem.attributes["test"], false);
+  if (importedNode.firstChild.nodeValue != "baz")
+    throw "wrong imported attribute child: '" + importedNode.firstChild.nodeValue + "'";
+
+  dstElem.setAttributeNode(importedNode);
+  if (dstElem.getAttribute("test") != "baz")
+    throw "wrong imported attribute value: '" + dstElem.getAttribute("test") + "'";
+
+  document.write("<div>SUCCESS</div>");
+} catch (ex) {
+  document.write("<div>" + ex + "</div>");
+}
+</script>
diff --git a/LayoutTests/fast/dom/import-document-fragment-expected.txt b/LayoutTests/fast/dom/import-document-fragment-expected.txt
new file mode 100644 (file)
index 0000000..ff43ca4
--- /dev/null
@@ -0,0 +1 @@
+SUCCESS
diff --git a/LayoutTests/fast/dom/import-document-fragment.html b/LayoutTests/fast/dom/import-document-fragment.html
new file mode 100644 (file)
index 0000000..3a0a148
--- /dev/null
@@ -0,0 +1,21 @@
+<script>
+if (window.layoutTestController)
+  layoutTestController.dumpAsText();
+
+try {
+  var xmld = new DOMParser().parseFromString( "<doc/>", "text/xml");
+
+  var fragment = document.createDocumentFragment();
+  fragment.appendChild(document.createTextNode("1"));
+  fragment.appendChild(document.createTextNode("2"));
+
+  var importedFragment = xmld.importNode(fragment, true);
+  xmld.firstChild.appendChild(importedFragment);
+  if (xmld.firstChild.textContent != "12")
+    throw "wrong imported DOM tree: '" + xmld.firstChild.textContent + "'";
+
+  document.write("<div>SUCCESS</div>");
+} catch (ex) {
+  document.write("<div>" + ex + "</div>");
+}
+</script>
index fc5062f..4e95976 100644 (file)
@@ -1,3 +1,16 @@
+2007-10-25  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15650
+        XML attribute nodes are not importable
+
+        Tests: fast/dom/import-attribute-node.html
+               fast/dom/import-document-fragment.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::importNode): Implemented for Attribute and DocumentFragment nodes.
+
 2007-10-25  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
index 9562c57..0ef131a 100644 (file)
@@ -592,10 +592,10 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo
         case COMMENT_NODE:
             return createComment(importedNode->nodeValue());
         case ELEMENT_NODE: {
-            Element *oldElement = static_cast<Element *>(importedNode);
+            Element* oldElement = static_cast<Element*>(importedNode);
             RefPtr<Element> newElement = createElementNS(oldElement->namespaceURI(), oldElement->tagQName().toString(), ec);
                         
-            if (ec != 0)
+            if (ec)
                 return 0;
 
             NamedAttrMap* attrs = oldElement->attributes(true);
@@ -604,7 +604,7 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo
                 for (unsigned i = 0; i < length; i++) {
                     Attribute* attr = attrs->attributeItem(i);
                     newElement->setAttribute(attr->name(), attr->value().impl(), ec);
-                    if (ec != 0)
+                    if (ec)
                         return 0;
                 }
             }
@@ -614,22 +614,43 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo
             if (deep) {
                 for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
                     RefPtr<Node> newChild = importNode(oldChild, true, ec);
-                    if (ec != 0)
+                    if (ec)
                         return 0;
                     newElement->appendChild(newChild.release(), ec);
-                    if (ec != 0)
+                    if (ec)
                         return 0;
                 }
             }
 
             return newElement.release();
         }
-        case ATTRIBUTE_NODE:
+        case ATTRIBUTE_NODE: {
+            RefPtr<Attr> newAttr = new Attr(0, this, static_cast<Attr*>(importedNode)->attr()->clone());
+            newAttr->createTextChild();
+            return newAttr.release();
+        }
+        case DOCUMENT_FRAGMENT_NODE: {
+            DocumentFragment* oldFragment = static_cast<DocumentFragment*>(importedNode);
+            RefPtr<DocumentFragment> newFragment = createDocumentFragment();
+            if (deep) {
+                for (Node* oldChild = oldFragment->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
+                    RefPtr<Node> newChild = importNode(oldChild, true, ec);
+                    if (ec)
+                        return 0;
+                    newFragment->appendChild(newChild.release(), ec);
+                    if (ec)
+                        return 0;
+                }
+            }
+            
+            return newFragment.release();
+        }
         case ENTITY_NODE:
+        case NOTATION_NODE:
+            // FIXME: It should be possible to import these node types, however in DOM3 the DocumentType is readonly, so there isn't much sense in doing that.
+            // Ability to add these imported nodes to a DocumentType will be considered for addition to a future release of the DOM.
         case DOCUMENT_NODE:
         case DOCUMENT_TYPE_NODE:
-        case DOCUMENT_FRAGMENT_NODE:
-        case NOTATION_NODE:
         case XPATH_NAMESPACE_NODE:
             break;
     }