Changeset 29952 in webkit


Ignore:
Timestamp:
Feb 3, 2008 3:46:58 PM (16 years ago)
Author:
eric@webkit.org
Message:

Reviewed by darin.

Make createElementNS and createAttributeNS follow the (vague) DOM Core 2 spec
by throwing exceptions for more types of invalid qualified names.
http://bugs.webkit.org/show_bug.cgi?id=16833

Tests: fast/dom/Document/createAttributeNS-namespace-err.html

fast/dom/Document/createElementNS-namespace-err.html

  • dom/Document.cpp: (WebCore::Document::createElement): (WebCore::hasNamespaceError): (WebCore::Document::createElementNS): (WebCore::Document::createAttributeNS):
  • dom/Document.idl:
Location:
trunk
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r29947 r29952  
     12008-02-03  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by darin.
     4
     5        Make createElementNS and createAttributeNS follow the (vague) DOM Core 2 spec
     6        by throwing exceptions for more types of invalid qualified names.
     7        http://bugs.webkit.org/show_bug.cgi?id=16833
     8       
     9        These tests were originally from Hixie's Acid3, then I added some, then Josh
     10        from mozilla added more. We pass all of mine and Hixie's.  Some of Josh's
     11        still fail (extreme edge cases, such as *which* exception to throw when
     12        a QName is a valid XML name but invalid QName, etc.)
     13        The "failure" results are still being checked in, perhaps some day we'll "fix" them.
     14
     15        * dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt:
     16        * fast/dom/Document/createAttributeNS-namespace-err-expected.txt: Added.
     17        * fast/dom/Document/createAttributeNS-namespace-err.html: Added.
     18        * fast/dom/Document/createElementNS-namespace-err-expected.txt: Added.
     19        * fast/dom/Document/createElementNS-namespace-err.html: Added.
     20        * fast/dom/Document/resources/TEMPLATE.html: Added.
     21        * fast/dom/Document/resources/createAttributeNS-namespace-err.js: Added.
     22        * fast/dom/Document/resources/createElementNS-namespace-err.js: Added.
     23
    1242008-02-03  Darin Adler  <darin@apple.com>
    225
  • trunk/LayoutTests/dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt

    r11962 r29952  
    11Test    http://www.w3.org/2001/DOM-Test-Suite/level3/core/documentsetstricterrorchecking02
    2 Status  failure
    3 Message NAMESPACE_ERR_documentsetstricterrorchecking02: assertTrue failed
     2Status  Success
  • trunk/WebCore/ChangeLog

    r29951 r29952  
     12008-02-03  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by darin.
     4
     5        Make createElementNS and createAttributeNS follow the (vague) DOM Core 2 spec
     6        by throwing exceptions for more types of invalid qualified names.
     7        http://bugs.webkit.org/show_bug.cgi?id=16833
     8
     9        Tests: fast/dom/Document/createAttributeNS-namespace-err.html
     10               fast/dom/Document/createElementNS-namespace-err.html
     11
     12        * dom/Document.cpp:
     13        (WebCore::Document::createElement):
     14        (WebCore::hasNamespaceError):
     15        (WebCore::Document::createElementNS):
     16        (WebCore::Document::createAttributeNS):
     17        * dom/Document.idl:
     18
    1192008-02-03  Nikolas Zimmermann  <zimmermann@kde.org>
    220
  • trunk/WebCore/dom/Document.cpp

    r29905 r29952  
    103103#include "WheelEvent.h"
    104104#include "XMLHttpRequest.h"
     105#include "XMLNames.h"
    105106#include "XMLTokenizer.h"
    106107#include "kjs_binding.h"
     
    509510        }
    510511
    511         return HTMLElementFactory::createHTMLElement(AtomicString(name), this, 0, false);
     512        return HTMLElementFactory::createHTMLElement(name, this, 0, false);
    512513    } else
    513514        return createElementNS(nullAtom, name, ec);
     
    700701}
    701702
     703static bool hasNamespaceError(const QualifiedName& qName)
     704{
     705    static const AtomicString xmlnsNamespaceURI = "http://www.w3.org/2000/xmlns/";
     706    static const AtomicString xmlns = "xmlns";
     707    static const AtomicString xml = "xml";
     708
     709    // These checks are from DOM Core Level 2, createElementNS
     710    // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS
     711    if (qName.prefix() == emptyAtom) // createElementNS(null, ":div")
     712        return true;
     713    if (qName.localName().isEmpty()) // createElementNS(null, ""), createElementNS(null, null), createElementNS()
     714        return true;
     715    if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div")
     716        return true;
     717    if (qName.prefix() == xml && qName.namespaceURI() != XMLNames::xmlNamespaceURI) // createElementNS("http://www.example.com", "xml:lang")
     718        return true;
     719
     720    // Required by DOM Level 3 Core and unspecified by DOM Level 2 Core:
     721    // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
     722    // createElementNS("http://www.w3.org/2000/xmlns/", "foo:bar"), createElementNS(null, "xmlns:bar")
     723    if ((qName.prefix() == xmlns && qName.namespaceURI() != xmlnsNamespaceURI) || (qName.prefix() != xmlns && qName.namespaceURI() == xmlnsNamespaceURI))
     724        return true;
     725
     726    return false;
     727}
     728
    702729// FIXME: This should really be in a possible ElementFactory class
    703730PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool createdByParser, ExceptionCode& ec)
     
    716743        e = new Element(qName, document());
    717744   
     745    // FIXME: The element factories should be fixed to not ignore qName.prefix()
     746    // Instead they should pass the entire qName into element creation so we don't
     747    // need to manually set the prefix after creation.
     748    // Then this code can become ASSERT(qName == e.qname());
     749    // and Document::createElement can stop taking ExceptionCode& as well.
    718750    if (e && !qName.prefix().isNull()) {
    719751        ec = 0;
     
    721753        if (ec)
    722754            return 0;
    723     }   
     755    }
    724756   
    725757    return e.release();
    726758}
    727759
    728 PassRefPtr<Element> Document::createElementNS(const String &_namespaceURI, const String &qualifiedName, ExceptionCode& ec)
     760PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec)
    729761{
    730762    String prefix, localName;
     
    734766    }
    735767
    736     RefPtr<Element> e;
    737     QualifiedName qName = QualifiedName(AtomicString(prefix), AtomicString(localName), AtomicString(_namespaceURI));
    738    
     768    QualifiedName qName(prefix, localName, namespaceURI);
     769    if (hasNamespaceError(qName)) {
     770        ec = NAMESPACE_ERR;
     771        return 0;
     772    }
     773
    739774    return createElement(qName, false, ec);
    740775}
    741776
    742 Element *Document::getElementById(const AtomicString& elementId) const
     777Element* Document::getElementById(const AtomicString& elementId) const
    743778{
    744779    if (elementId.length() == 0)
     
    26782713}
    26792714
    2680 bool Document::parseQualifiedName(const String &qualifiedName, String &prefix, String &localName)
     2715bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName)
    26812716{
    26822717    unsigned length = qualifiedName.length();
     
    33913426}
    33923427
    3393 PassRefPtr<Attr> Document::createAttributeNS(const String &namespaceURI, const String &qualifiedName, ExceptionCode& ec)
    3394 {
    3395     if (qualifiedName.isNull()) {
     3428PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec)
     3429{
     3430    String prefix, localName;
     3431    if (!parseQualifiedName(qualifiedName, prefix, localName)) {
     3432        ec = INVALID_CHARACTER_ERR;
     3433        return 0;
     3434    }
     3435
     3436    QualifiedName qName(prefix, localName, namespaceURI);
     3437    if (hasNamespaceError(qName)) {
    33963438        ec = NAMESPACE_ERR;
    33973439        return 0;
    33983440    }
    33993441
    3400     String localName = qualifiedName;
    3401     String prefix;
    3402     int colonpos;
    3403     if ((colonpos = qualifiedName.find(':')) >= 0) {
    3404         prefix = qualifiedName.substring(0, colonpos);
    3405         localName = qualifiedName.substring(colonpos + 1);
    3406     }
    3407 
    3408     if (!isValidName(localName)) {
    3409         ec = INVALID_CHARACTER_ERR;
     3442    // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrAttrNS
     3443    if (qName.localName() == "xmlns" && qName.namespaceURI() != "http://www.w3.org/2000/xmlns/") {
     3444        ec = NAMESPACE_ERR;
    34103445        return 0;
    34113446    }
    3412    
     3447
    34133448    // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware.  There's no harm to XML
    34143449    // documents if we're wrong.
    3415     return new Attr(0, this, new MappedAttribute(QualifiedName(prefix, localName, namespaceURI), StringImpl::empty()));
     3450    return new Attr(0, this, new MappedAttribute(qName, StringImpl::empty()));
    34163451}
    34173452
  • trunk/WebCore/dom/Document.idl

    r29672 r29952  
    5656            raises (DOMException);
    5757        [OldStyleObjC] Element createElementNS(in [ConvertNullToNullString] DOMString namespaceURI,
    58                                                in DOMString qualifiedName)
     58                                               in [ConvertNullToNullString] DOMString qualifiedName)
    5959            raises (DOMException);
    6060        [OldStyleObjC] Attr createAttributeNS(in [ConvertNullToNullString] DOMString namespaceURI,
    61                                               in DOMString qualifiedName)
     61                                              in [ConvertNullToNullString] DOMString qualifiedName)
    6262            raises (DOMException);
    6363        [OldStyleObjC] NodeList getElementsByTagNameNS(in [ConvertNullToNullString] DOMString namespaceURI,
Note: See TracChangeset for help on using the changeset viewer.