Commit 7ce64cf7 authored by weinig's avatar weinig

LayoutTests:

        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: http://svn.webkit.org/repository/webkit/trunk@18085 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7802858
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
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">".
<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>
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.
<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>
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
......@@ -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));
......
/*
* 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
......@@ -21,16 +22,27 @@
#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
/*
* 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
......@@ -17,19 +18,23 @@
* 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
/*
* 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
......@@ -18,7 +19,10 @@
*/
module xpath {
interface [GenerateConstructor, CanBeConstructed] XMLSerializer {
DOMString serializeToString(in Node node);
DOMString serializeToString(in Node node)
raises(DOMException);
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment