Show
Ignore:
Timestamp:
03/22/08 02:50:54 (8 months ago)
Author:
eric@webkit.org
Message:

Reviewed by mjs.

Unify handling of NAMESPACE_ERR and fix Acid3 test 25
http://bugs.webkit.org/show_bug.cgi?id=16693

Test: fast/dom/DOMImplementation/createDocumentType-err.html

  • dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): (WebCore::DOMImplementation::createDocument):
  • dom/DOMImplementation.idl:
  • dom/Document.cpp: (WebCore::Document::hasPrefixNamespaceMismatch): (WebCore::Document::createElementNS): (WebCore::Document::parseQualifiedName): (WebCore::Document::createAttributeNS):
  • dom/Document.h:
  • dom/Element.cpp: (WebCore::Element::setAttributeNS):
  • editing/FormatBlockCommand.cpp: (WebCore::FormatBlockCommand::doApply):
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/dom/DOMImplementation.cpp

    r30923 r31231  
    5252 
    5353namespace WebCore { 
    54  
    55 // FIXME: An implementation of this is still waiting for me to understand the distinction between 
    56 // a "malformed" qualified name and one with bad characters in it. For example, is a second colon 
    57 // an illegal character or a malformed qualified name? This will determine both what parameters 
    58 // this function needs to take and exactly what it will do. Should also be exported so that 
    59 // Element can use it too. 
    60 static bool qualifiedNameIsMalformed(const String&) 
    61 { 
    62     return false; 
    63 } 
    6454 
    6555#if ENABLE(SVG) 
     
    207197    const String& publicId, const String& systemId, ExceptionCode& ec) 
    208198{ 
    209     // Not mentioned in spec: throw NAMESPACE_ERR if no qualifiedName supplied 
    210     if (qualifiedName.isNull()) { 
    211         ec = NAMESPACE_ERR; 
     199    String prefix, localName; 
     200    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec)) 
    212201        return 0; 
    213     } 
    214  
    215     // INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character. 
    216     String prefix, localName; 
    217     if (!Document::parseQualifiedName(qualifiedName, prefix, localName)) { 
    218         ec = INVALID_CHARACTER_ERR; 
    219         return 0; 
    220     } 
    221  
    222     // NAMESPACE_ERR: Raised if the qualifiedName is malformed. 
    223     if (qualifiedNameIsMalformed(qualifiedName)) { 
    224         ec = NAMESPACE_ERR; 
    225         return 0; 
    226     } 
    227  
    228     ec = 0; 
     202 
    229203    return new DocumentType(this, 0, qualifiedName, publicId, systemId); 
    230204} 
     
    239213    const String& qualifiedName, DocumentType* doctype, ExceptionCode& ec) 
    240214{ 
    241     if (!qualifiedName.isEmpty()) { 
    242         // INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character. 
    243         String prefix, localName; 
    244         if (!Document::parseQualifiedName(qualifiedName, prefix, localName)) { 
    245             ec = INVALID_CHARACTER_ERR; 
    246             return 0; 
    247         } 
    248  
    249         // NAMESPACE_ERR: 
    250         // - Raised if the qualifiedName is malformed, 
    251         // - if the qualifiedName has a prefix and the namespaceURI is null, or 
    252         // - if the qualifiedName has a prefix that is "xml" and the namespaceURI is different 
    253         //   from "http://www.w3.org/XML/1998/namespace" [Namespaces]. 
    254         int colonpos = qualifiedName.find(':');     
    255         if (qualifiedNameIsMalformed(qualifiedName) || 
    256             (colonpos >= 0 && namespaceURI.isNull()) || 
    257             (colonpos == 3 && qualifiedName[0] == 'x' && qualifiedName[1] == 'm' && qualifiedName[2] == 'l' && 
    258 #if ENABLE(SVG) 
    259              namespaceURI != SVGNames::svgNamespaceURI && 
    260 #endif 
    261              namespaceURI != XMLNames::xmlNamespaceURI)) { 
    262  
    263             ec = NAMESPACE_ERR; 
    264             return 0; 
    265         } 
    266     } 
    267      
    268215    // WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a different document or was 
    269216    // created from a different implementation. 
    270     if (doctype && (doctype->document() || doctype->implementation() != this)) { 
    271         ec = WRONG_DOCUMENT_ERR; 
    272         return 0; 
    273     } 
     217    bool shouldThrowWrongDocErr = false; 
     218    if (doctype && (doctype->document() || doctype->implementation() != this)) 
     219        shouldThrowWrongDocErr = true; 
    274220 
    275221    RefPtr<Document> doc; 
     
    288234        doc->addChild(doctype); 
    289235 
    290     if (!qualifiedName.isEmpty()) 
     236    if (!qualifiedName.isEmpty()) { 
    291237        doc->addChild(doc->createElementNS(namespaceURI, qualifiedName, ec)); 
    292      
    293     ec = 0; 
     238        if (ec != 0) 
     239            return 0; 
     240    } 
     241 
     242    // Hixie's interpretation of the DOM Core spec suggests we should prefer 
     243    // other exceptions to WRONG_DOCUMENT_ERR (based on order mentioned in spec) 
     244    if (shouldThrowWrongDocErr) { 
     245        ec = WRONG_DOCUMENT_ERR; 
     246        return 0; 
     247    } 
     248 
    294249    return doc.release(); 
    295250}