Commit a75a29b0 authored by andersca's avatar andersca

2006-01-03 Anders Carlsson <andersca@mac.com>

        Reviewed by Maciej.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5378
        createDocument fails with DOM Exception 5 when passed empty qname

        * khtml/ecma/kjs_dom.cpp:
        (KJS::DOMDOMImplementationProtoFunc::callAsFunction):
        When passing null to createDocument, pass a null DOMString, and not
        a DOMString containing the text "null".

        * khtml/xml/dom_docimpl.cpp:
        (DOMImplementationImpl::createDocument):
        Only validate the qualifiedName if it's not null or empty. Also, do not
        create the document element if the qualifiedName is null or empty.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@11855 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ef508986
2006-01-03 Anders Carlsson <andersca@mac.com>
Reviewed by Maciej.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5378
createDocument fails with DOM Exception 5 when passed empty qname
* khtml/ecma/kjs_dom.cpp:
(KJS::DOMDOMImplementationProtoFunc::callAsFunction):
When passing null to createDocument, pass a null DOMString, and not
a DOMString containing the text "null".
* khtml/xml/dom_docimpl.cpp:
(DOMImplementationImpl::createDocument):
Only validate the qualifiedName if it's not null or empty. Also, do not
create the document element if the qualifiedName is null or empty.
2006-01-03 Eric Seidel <eseidel@apple.com>
Reviewed by darin.
......
......@@ -1346,8 +1346,8 @@ JSValue *DOMDOMImplementationProtoFunc::callAsFunction(ExecState *exec, JSObject
return getDOMNode(exec, implementation.createDocumentType(args[0]->toString(exec).domString(),
args[1]->toString(exec).domString(), args[2]->toString(exec).domString(), exception));
case DOMDOMImplementation::CreateDocument: // DOM2
return getDOMNode(exec, implementation.createDocument(args[0]->toString(exec).domString(),
args[1]->toString(exec).domString(), toDocumentType(args[2]), exception));
return getDOMNode(exec, implementation.createDocument(valueToStringWithNullCheck(exec, args[0]),
valueToStringWithNullCheck(exec, args[1]), toDocumentType(args[2]), exception));
case DOMDOMImplementation::CreateCSSStyleSheet: // DOM2
return getDOMStyleSheet(exec, implementation.createCSSStyleSheet(args[0]->toString(exec).domString(), args[1]->toString(exec).domString(), exception));
case DOMDOMImplementation::CreateHTMLDocument: // DOM2-HTML
......
......@@ -263,41 +263,37 @@ DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceU
{
exceptioncode = 0;
// Not mentioned in spec: throw NAMESPACE_ERR if no qualifiedName supplied
if (qualifiedName.isNull()) {
exceptioncode = DOMException::NAMESPACE_ERR;
return 0;
}
// INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
DOMString prefix, localName;
if (!DocumentImpl::parseQualifiedName(qualifiedName, prefix, localName)) {
exceptioncode = DOMException::INVALID_CHARACTER_ERR;
return 0;
}
// NAMESPACE_ERR:
// - Raised if the qualifiedName is malformed,
// - if the qualifiedName has a prefix and the namespaceURI is null, or
// - if the qualifiedName has a prefix that is "xml" and the namespaceURI is different
// from "http://www.w3.org/XML/1998/namespace" [Namespaces].
int colonpos = -1;
uint i;
DOMStringImpl *qname = qualifiedName.impl();
for (i = 0; i < qname->l && colonpos < 0; i++) {
if ((*qname)[i] == ':')
colonpos = i;
}
if (!qualifiedName.isEmpty()) {
// INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
DOMString prefix, localName;
if (!DocumentImpl::parseQualifiedName(qualifiedName, prefix, localName)) {
exceptioncode = DOMException::INVALID_CHARACTER_ERR;
return 0;
}
if (qualifiedNameIsMalformed(qualifiedName) ||
(colonpos >= 0 && namespaceURI.isNull()) ||
(colonpos == 3 && qualifiedName[0] == 'x' && qualifiedName[1] == 'm' && qualifiedName[2] == 'l' &&
namespaceURI != "http://www.w3.org/XML/1998/namespace")) {
// NAMESPACE_ERR:
// - Raised if the qualifiedName is malformed,
// - if the qualifiedName has a prefix and the namespaceURI is null, or
// - if the qualifiedName has a prefix that is "xml" and the namespaceURI is different
// from "http://www.w3.org/XML/1998/namespace" [Namespaces].
int colonpos = -1;
uint i;
DOMStringImpl *qname = qualifiedName.impl();
for (i = 0; i < qname->l && colonpos < 0; i++) {
if ((*qname)[i] == ':')
colonpos = i;
}
if (qualifiedNameIsMalformed(qualifiedName) ||
(colonpos >= 0 && namespaceURI.isNull()) ||
(colonpos == 3 && qualifiedName[0] == 'x' && qualifiedName[1] == 'm' && qualifiedName[2] == 'l' &&
namespaceURI != "http://www.w3.org/XML/1998/namespace")) {
exceptioncode = DOMException::NAMESPACE_ERR;
return 0;
exceptioncode = DOMException::NAMESPACE_ERR;
return 0;
}
}
// WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a different document or was
// created from a different implementation.
if (doctype && (doctype->getDocument() || doctype->implementation() != this)) {
......@@ -312,8 +308,10 @@ DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceU
if (doctype)
doc->setDocType(new DocumentTypeImpl(doc, *doctype));
ElementImpl *rootElement = doc->createElementNS(namespaceURI, qualifiedName, exceptioncode);
doc->addChild(rootElement);
if (!qualifiedName.isEmpty()) {
ElementImpl *rootElement = doc->createElementNS(namespaceURI, qualifiedName, exceptioncode);
doc->addChild(rootElement);
}
return doc;
}
......
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