LayoutTests:
authorweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2006 21:12:48 +0000 (21:12 +0000)
committerweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2006 21:12:48 +0000 (21:12 +0000)
        Reviewed by Geoff.

        Testcases for http://bugs.webkit.org/show_bug.cgi?id=11777
        Crash when using XMLSerializer.serializeToString() on
        documentless, DocumentType nodes.

        * fast/dom/XMLSerializer-doctype-expected.txt: Added.
        * fast/dom/XMLSerializer-doctype.html: Added.
        * fast/dom/XMLSerializer-doctype2-expected.txt: Added.
        * fast/dom/XMLSerializer-doctype2.html: Added.

WebCore:

        Reviewed by Geoff.

        Fix for http://bugs.webkit.org/show_bug.cgi?id=11777
        Crash when using XMLSerializer.serializeToString() on
        documentless, DocumentType nodes.

        Test: fast/dom/XMLSerializer-doctype.html
        Test: fast/dom/XMLSerializer-doctype2.html

        * dom/DOMImplementation.cpp:
        (WebCore::DOMImplementation::createDocument): set the document of the
        DocumentType node to the new document.
        * xml/XMLSerializer.cpp: Cleanup.
        (WebCore::XMLSerializer::serializeToString): now throws an exception
        for documentless nodes.
        * xml/XMLSerializer.h: cleanup
        * xml/XMLSerializer.idl: add exception

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/XMLSerializer-doctype-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/XMLSerializer-doctype.html [new file with mode: 0644]
LayoutTests/fast/dom/XMLSerializer-doctype2-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/XMLSerializer-doctype2.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/DOMImplementation.cpp
WebCore/xml/XMLSerializer.cpp
WebCore/xml/XMLSerializer.h
WebCore/xml/XMLSerializer.idl

index b0a33a5d864a556e24fe4c431d3e23fde05a9a42..e2cd8a4c4601eeeeeb74b9141ea45f9d514a0fe0 100644 (file)
@@ -1,3 +1,16 @@
+2006-12-08  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Geoff.
+
+        Testcases for http://bugs.webkit.org/show_bug.cgi?id=11777
+        Crash when using XMLSerializer.serializeToString() on
+        documentless, DocumentType nodes.
+
+        * fast/dom/XMLSerializer-doctype-expected.txt: Added.
+        * fast/dom/XMLSerializer-doctype.html: Added.
+        * fast/dom/XMLSerializer-doctype2-expected.txt: Added.
+        * fast/dom/XMLSerializer-doctype2.html: Added.
+
 2006-12-08  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by john
diff --git a/LayoutTests/fast/dom/XMLSerializer-doctype-expected.txt b/LayoutTests/fast/dom/XMLSerializer-doctype-expected.txt
new file mode 100644 (file)
index 0000000..d5f4db9
--- /dev/null
@@ -0,0 +1,3 @@
+This tests XMLSerializer.serializeToString() on a DocumentType node that has a document associated with it.
+PASS: the DocumentType node has been successfully serialize to "<!DOCTYPE aDocTypeName PUBLIC "aPublicID" "aSystemID">".
+
diff --git a/LayoutTests/fast/dom/XMLSerializer-doctype.html b/LayoutTests/fast/dom/XMLSerializer-doctype.html
new file mode 100644 (file)
index 0000000..5e6f202
--- /dev/null
@@ -0,0 +1,33 @@
+<html>
+<head>
+    <script>
+        function debug(str) {
+            li = document.createElement('li');
+            li.appendChild(document.createTextNode(str));
+            document.getElementById('console').appendChild(li);
+        }
+
+        function runTests() {
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+            }
+
+            var docType = window.document.implementation.createDocumentType("aDocTypeName", "aPublicID", "aSystemID");
+            var doc = window.document.implementation.createDocument("", "", docType);
+
+            var serializer = new XMLSerializer();
+
+            var result = serializer.serializeToString(docType);
+            if (result == '<!DOCTYPE aDocTypeName PUBLIC "aPublicID" "aSystemID">')
+                debug('PASS: the DocumentType node has been successfully serialize to "' + result + '".');
+            else
+                debug('FAIL: the DocumentType node has not been successfully serialized.');
+        }
+    </script>
+</head>
+<body onload="runTests()">
+This tests XMLSerializer.serializeToString() on a DocumentType node that has a document associated with it.
+<ul id="console">
+</ul>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/XMLSerializer-doctype2-expected.txt b/LayoutTests/fast/dom/XMLSerializer-doctype2-expected.txt
new file mode 100644 (file)
index 0000000..de595f6
--- /dev/null
@@ -0,0 +1,3 @@
+This tests XMLSerializer.serializeToString() on a DocumentType node that does not have a document associated with it. It should throw an INVALID_ACCESS_ERR DOMException.
+PASS: an Error: INVALID_ACCESS_ERR: DOM Exception 15 was thrown as expected.
+
diff --git a/LayoutTests/fast/dom/XMLSerializer-doctype2.html b/LayoutTests/fast/dom/XMLSerializer-doctype2.html
new file mode 100644 (file)
index 0000000..efe1cc6
--- /dev/null
@@ -0,0 +1,37 @@
+<html>
+<head>
+    <script>
+        function debug(str) {
+            li = document.createElement('li');
+            li.appendChild(document.createTextNode(str));
+            document.getElementById('console').appendChild(li);
+        }
+
+        function runTests() {
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+
+            var docType = window.document.implementation.createDocumentType("aDocTypeName", "aPublicID", "aSystemID");
+
+            var serializer = new XMLSerializer();
+
+            try {
+                var text = serializer.serializeToString(docType);
+                debug("FAIL: XMLSerializer.serializeToString() should throw an exception if it tries to serialize a documentless DocumentType node.");
+            } catch (e) {
+                if (e == "Error: INVALID_ACCESS_ERR: DOM Exception 15")
+                    debug("PASS: an " + e + " was thrown as expected.")
+                else
+                    debug("FAIL: XMLSerializer.serializeToString() should throw an INVALID_ACCESS_ERR DOMExeption if it tries to serialize a documentless DocumentType node.");
+            }
+        }
+    </script>
+</head>
+<body onload="runTests()">
+This tests XMLSerializer.serializeToString() on a DocumentType node that does not have a document associated
+with it.  It should throw an INVALID_ACCESS_ERR DOMException.
+
+<ul id="console">
+</ul>
+</body>
+</html>
index e8d21f6b669d06a65b297d61eca64695cdf60ede..50c626c1fc99f52188f66be6fdb2ee879aa05462 100644 (file)
@@ -1,3 +1,23 @@
+2006-12-08  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Geoff.
+
+        Fix for http://bugs.webkit.org/show_bug.cgi?id=11777
+        Crash when using XMLSerializer.serializeToString() on
+        documentless, DocumentType nodes.
+
+        Test: fast/dom/XMLSerializer-doctype.html
+        Test: fast/dom/XMLSerializer-doctype2.html
+
+        * dom/DOMImplementation.cpp:
+        (WebCore::DOMImplementation::createDocument): set the document of the 
+        DocumentType node to the new document.
+        * xml/XMLSerializer.cpp: Cleanup.
+        (WebCore::XMLSerializer::serializeToString): now throws an exception
+        for documentless nodes. 
+        * xml/XMLSerializer.h: cleanup
+        * xml/XMLSerializer.idl: add exception
+
 2006-12-07  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by john
index 52142a1d05e65fad8dc7331d2624916577c7d6d1..058b1012fe732ebca17d3e22a6c16ac09b25e670 100644 (file)
@@ -5,6 +5,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -272,8 +273,10 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& namespaceUR
         doc = new Document(this, 0);
 
     // now get the interesting parts of the doctype
-    if (doctype)
-        doc->setDocType(new DocumentType(doc.get(), *doctype));
+    if (doctype) {
+        doc->setDocType(doctype);
+        doctype->setDocument(doc.get());
+    }
 
     if (!qualifiedName.isEmpty())
         doc->addChild(doc->createElementNS(namespaceURI, qualifiedName, ec));
index 2059c61447845bfad558a5d9de22048c75bc6370..ff0601a77f565eb174c134d04a8aec85d3bc6374 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  This file is part of the KDE libraries
  *  Copyright (C) 2003, 2006 Apple Computer, Inc.
+ *  Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
 #include "XMLSerializer.h"
 
 #include "Document.h"
+#include "ExceptionCode.h"
 #include "markup.h"
 
 namespace WebCore {
 
-String XMLSerializer::serializeToString(Node* node)
+String XMLSerializer::serializeToString(Node* node, ExceptionCode& ec)
 {
     if (!node)
         return String();
-    
+
+    if (!node->document()) {
+        // Due to the fact that DocumentType nodes are created by the DOMImplementation
+        // and not the Document, it is possible for it to not have a Document associated
+        // with it.  It should be the only type of node where this is possible.
+        ASSERT(node->nodeType() == Node::DOCUMENT_TYPE_NODE);
+
+        ec = INVALID_ACCESS_ERR;
+        return String();
+    }
+
     return createMarkup(node);
 }
 
-}
+} // namespace WebCore
index 7771fa680b0f6ceca8904d91a4771e6d6162779f..9aa7da433f1bfad85f849b34f4727dd8bc35131c 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  This file is part of the KDE libraries
  *  Copyright (C) 2003, 2006 Apple Computer, Inc.
+ *  Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef XMLSerializer_H
-#define XMLSerializer_H
+#ifndef XMLSerializer_h
+#define XMLSerializer_h
 
 #include "Shared.h"
 #include "PlatformString.h"
 
 namespace WebCore {
+
+    typedef int ExceptionCode;
+
     class Node;
-    
+
     class XMLSerializer : public Shared<XMLSerializer> {
     public:
-        String serializeToString(Node*);
+        String serializeToString(Node*, ExceptionCode&);
     };
-}
 
-#endif // XMLSerializer.h
+} // namespace WebCore
+
+#endif // XMLSerializer_h
index 8bed5ffbfeee0892873d17eb0e54cbdc69f87609..0adb9cc734df89720ef1ad62df5400557e79675d 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  */
 
 module xpath {
+
     interface [GenerateConstructor, CanBeConstructed] XMLSerializer {
-        DOMString serializeToString(in Node node);
+        DOMString serializeToString(in Node node)
+            raises(DOMException);
     };
+
 }