Changeset 31231 in webkit


Ignore:
Timestamp:
Mar 22, 2008 2:50:54 AM (16 years 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):
Location:
trunk
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r31230 r31231  
     12008-03-22  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by mjs.
     4
     5        Unify handling of NAMESPACE_ERR and fix Acid3 test 25
     6        http://bugs.webkit.org/show_bug.cgi?id=16693
     7
     8        * fast/dom/DOMImplementation/createDocumentType-err-expected.txt: Added.
     9        * fast/dom/DOMImplementation/createDocumentType-err.html: Copied from LayoutTests/fast/dom/DOMException/EventException.html.
     10        * fast/dom/DOMImplementation/resources/TEMPLATE.html: Copied from LayoutTests/fast/dom/Document/resources/TEMPLATE.html.
     11        * fast/dom/DOMImplementation/resources/createDocumentType-err.js: Added.
     12        * fast/dom/Document/createAttributeNS-namespace-err-expected.txt:
     13        * fast/dom/Document/createElementNS-namespace-err-expected.txt:
     14
    1152008-03-22  Eric Seidel  <eric@webkit.org>
    216
  • trunk/LayoutTests/fast/dom/Document/createAttributeNS-namespace-err-expected.txt

    r31230 r31231  
    2929PASS createAttributeNS("http://example.com/", "div:"); threw NAMESPACE_ERR
    3030PASS createAttributeNS(null, "d:iv"); threw NAMESPACE_ERR
    31 FAIL createAttributeNS(null, "a:b:c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    32 FAIL createAttributeNS("http://example.com/", "a:b:c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    33 FAIL createAttributeNS(null, "a::c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    34 FAIL createAttributeNS("http://example.com/", "a::c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
     31PASS createAttributeNS(null, "a:b:c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     32PASS createAttributeNS("http://example.com/", "a:b:c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     33PASS createAttributeNS(null, "a::c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     34PASS createAttributeNS("http://example.com/", "a::c"); valid XML name, invalid QName; threw NAMESPACE_ERR
    3535PASS createAttributeNS("http://example.com/", "a:0"); valid XML name, not a valid QName; threw INVALID_CHARACTER_ERR
    3636PASS createAttributeNS("http://example.com/", "0:a"); 0 at start makes it not a valid XML name; threw INVALID_CHARACTER_ERR
  • trunk/LayoutTests/fast/dom/Document/createElementNS-namespace-err-expected.txt

    r31230 r31231  
    3030PASS createElementNS("http://example.com/", "div:"); threw NAMESPACE_ERR
    3131PASS createElementNS(null, "d:iv"); threw NAMESPACE_ERR
    32 FAIL createElementNS(null, "a:b:c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    33 FAIL createElementNS("http://example.com/", "a:b:c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    34 FAIL createElementNS(null, "a::c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
    35 FAIL createElementNS("http://example.com/", "a::c"); valid XML name, invalid QName; expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
     32PASS createElementNS(null, "a:b:c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     33PASS createElementNS("http://example.com/", "a:b:c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     34PASS createElementNS(null, "a::c"); valid XML name, invalid QName; threw NAMESPACE_ERR
     35PASS createElementNS("http://example.com/", "a::c"); valid XML name, invalid QName; threw NAMESPACE_ERR
    3636PASS createElementNS("http://example.com/", "a:0"); valid XML name, not a valid QName; threw INVALID_CHARACTER_ERR
    3737PASS createElementNS("http://example.com/", "0:a"); 0 at start makes it not a valid XML name; threw INVALID_CHARACTER_ERR
  • trunk/WebCore/ChangeLog

    r31230 r31231  
     12008-03-22  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by mjs.
     4
     5        Unify handling of NAMESPACE_ERR and fix Acid3 test 25
     6        http://bugs.webkit.org/show_bug.cgi?id=16693
     7
     8        Test: fast/dom/DOMImplementation/createDocumentType-err.html
     9
     10        * dom/DOMImplementation.cpp:
     11        (WebCore::DOMImplementation::createDocumentType):
     12        (WebCore::DOMImplementation::createDocument):
     13        * dom/DOMImplementation.idl:
     14        * dom/Document.cpp:
     15        (WebCore::Document::hasPrefixNamespaceMismatch):
     16        (WebCore::Document::createElementNS):
     17        (WebCore::Document::parseQualifiedName):
     18        (WebCore::Document::createAttributeNS):
     19        * dom/Document.h:
     20        * dom/Element.cpp:
     21        (WebCore::Element::setAttributeNS):
     22        * editing/FormatBlockCommand.cpp:
     23        (WebCore::FormatBlockCommand::doApply):
     24
    1252008-03-22  Eric Seidel  <eric@webkit.org>
    226
  • 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}
  • trunk/WebCore/dom/DOMImplementation.idl

    r27276 r31231  
    3434        // DOM Level 2
    3535
    36         [OldStyleObjC] DocumentType createDocumentType(in DOMString qualifiedName,
    37                                                        in DOMString publicId,
    38                                                        in DOMString systemId)
     36        [OldStyleObjC] DocumentType createDocumentType(in [ConvertUndefinedOrNullToNullString] DOMString qualifiedName,
     37                                                       in [ConvertUndefinedOrNullToNullString] DOMString publicId,
     38                                                       in [ConvertUndefinedOrNullToNullString] DOMString systemId)
    3939            raises(DOMException);
    4040        [OldStyleObjC] Document createDocument(in [ConvertNullToNullString] DOMString namespaceURI,
  • trunk/WebCore/dom/Document.cpp

    r31230 r31231  
    718718}
    719719
    720 static bool hasNamespaceError(const QualifiedName& qName)
    721 {
    722     static const AtomicString xmlnsNamespaceURI = "http://www.w3.org/2000/xmlns/";
    723     static const AtomicString xmlns = "xmlns";
    724     static const AtomicString xml = "xml";
     720bool Document::hasPrefixNamespaceMismatch(const QualifiedName& qName)
     721{
     722    static const AtomicString xmlnsNamespaceURI("http://www.w3.org/2000/xmlns/");
     723    static const AtomicString xmlns("xmlns");
     724    static const AtomicString xml("xml");
    725725
    726726    // These checks are from DOM Core Level 2, createElementNS
    727727    // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS
    728     if (qName.prefix() == emptyAtom) // createElementNS(null, ":div")
    729         return true;
    730     if (qName.localName().isEmpty()) // createElementNS(null, ""), createElementNS(null, null), createElementNS()
    731         return true;
    732728    if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div")
    733729        return true;
     
    778774{
    779775    String prefix, localName;
    780     if (!parseQualifiedName(qualifiedName, prefix, localName)) {
    781         ec = INVALID_CHARACTER_ERR;
     776    if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
    782777        return 0;
    783     }
    784778
    785779    QualifiedName qName(prefix, localName, namespaceURI);
    786     if (hasNamespaceError(qName)) {
     780    if (hasPrefixNamespaceMismatch(qName)) {
    787781        ec = NAMESPACE_ERR;
    788782        return 0;
     
    28202814}
    28212815
    2822 bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName)
     2816bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode& ec)
    28232817{
    28242818    unsigned length = qualifiedName.length();
    28252819
    2826     if (length == 0)
     2820    if (length == 0) {
     2821        ec = INVALID_CHARACTER_ERR;
    28272822        return false;
     2823    }
    28282824
    28292825    bool nameStart = true;
     
    28362832        U16_NEXT(s, i, length, c)
    28372833        if (c == ':') {
    2838             if (sawColon)
     2834            if (sawColon) {
     2835                ec = NAMESPACE_ERR;
    28392836                return false; // multiple colons: not allowed
     2837            }
    28402838            nameStart = true;
    28412839            sawColon = true;
    28422840            colonPos = i - 1;
    28432841        } else if (nameStart) {
    2844             if (!isValidNameStart(c))
     2842            if (!isValidNameStart(c)) {
     2843                ec = INVALID_CHARACTER_ERR;
    28452844                return false;
     2845            }
    28462846            nameStart = false;
    28472847        } else {
    2848             if (!isValidNamePart(c))
     2848            if (!isValidNamePart(c)) {
     2849                ec = INVALID_CHARACTER_ERR;
    28492850                return false;
     2851            }
    28502852        }
    28512853    }
     
    28562858    } else {
    28572859        prefix = qualifiedName.substring(0, colonPos);
     2860        if (prefix.isEmpty()) {
     2861            ec = NAMESPACE_ERR;
     2862            return false;
     2863        }
    28582864        localName = qualifiedName.substring(colonPos + 1);
     2865    }
     2866
     2867    if (localName.isEmpty()) {
     2868        ec = NAMESPACE_ERR;
     2869        return false;
    28592870    }
    28602871
     
    35283539{
    35293540    String prefix, localName;
    3530     if (!parseQualifiedName(qualifiedName, prefix, localName)) {
    3531         ec = INVALID_CHARACTER_ERR;
     3541    if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
    35323542        return 0;
    3533     }
    35343543
    35353544    QualifiedName qName(prefix, localName, namespaceURI);
    3536     if (hasNamespaceError(qName)) {
     3545    if (hasPrefixNamespaceMismatch(qName)) {
    35373546        ec = NAMESPACE_ERR;
    35383547        return 0;
  • trunk/WebCore/dom/Document.h

    r31144 r31231  
    593593
    594594    // The following breaks a qualified name into a prefix and a local name.
    595     // It also does a validity check, and returns false if the qualified name is invalid
    596     // (empty string or invalid characters).
    597     static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName);
     595    // It also does a validity check, and returns false if the qualified name
     596    // is invalid.  It also sets ExceptionCode when name is invalid.
     597    static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
     598   
     599    // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
     600    static bool hasPrefixNamespaceMismatch(const QualifiedName&);
    598601   
    599602    void addElementById(const AtomicString& elementId, Element *element);
  • trunk/WebCore/dom/Element.cpp

    r31181 r31231  
    10551055{
    10561056    String prefix, localName;
    1057     if (!Document::parseQualifiedName(qualifiedName, prefix, localName)) {
    1058         ec = INVALID_CHARACTER_ERR;
    1059         return;
    1060     }
    1061     setAttribute(QualifiedName(prefix, localName, namespaceURI), value.impl(), ec);
     1057    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
     1058        return;
     1059
     1060    QualifiedName qName(prefix, localName, namespaceURI);
     1061    setAttribute(qName, value.impl(), ec);
    10621062}
    10631063
  • trunk/WebCore/editing/FormatBlockCommand.cpp

    r29877 r31231  
    9292    if (endingSelection().isRange() && modifyRange())
    9393        return;
    94    
     94
     95    ExceptionCode ec;
    9596    String localName, prefix;
    96     if (!Document::parseQualifiedName(m_tagName, prefix, localName))
     97    if (!Document::parseQualifiedName(m_tagName, prefix, localName, ec))
    9798        return;
    98     QualifiedName qTypeOfBlock = QualifiedName(AtomicString(prefix), AtomicString(localName), xhtmlNamespaceURI);
    99    
     99    QualifiedName qTypeOfBlock(prefix, localName, xhtmlNamespaceURI);
     100
    100101    Node* refNode = enclosingBlockFlowElement(endingSelection().visibleStart());
    101102    if (refNode->hasTagName(qTypeOfBlock))
Note: See TracChangeset for help on using the changeset viewer.