[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:56:45 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 0833638fe8b47a440b7a2fdba73875698fd7ffe0
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Sep 21 03:53:06 2003 +0000

            Reviewed by Dave.
    
            - more fixes for the W3C DOM tests
    
            * khtml/dom/dom_doc.cpp: (Document::createAttributeNS): Check that the attribute name
            is valid and throw INVALID_CHARACTER_ERR if not.
    
            * khtml/dom/dom_element.cpp:
            (Element::removeAttributeNode): Get the attribute name properly. The old code would always
            get a 0, so this function would always fail.
            (Element::setAttributeNS): Check that the attribute name is valid and throw
            INVALID_CHARACTER_ERR if not.
            (Element::setAttributeNodeNS): Remove redundant exception checks that are also done by
            setNamedItem in the implementation. I had to change the implementation of one, so I decided
            it was better not to have any duplication.
    
            * khtml/xml/dom_docimpl.h: Added isValidName function.
            * khtml/xml/dom_docimpl.cpp:
            (DocumentImpl::createHTMLElement): Check that the attribute name is valid and throw
            INVALID_CHARACTER_ERR if not.
            (DocumentImpl::isValidName): Added. Used to check for valid names.
    
            * khtml/xml/dom_elementimpl.cpp:
            (NamedAttrMapImpl::setNamedItem): Don't do the document check until after checking for
            the "replace self" case. Otherwise we raise a spurious "in use" exception.
            (NamedAttrMapImpl::addAttribute): Point the new attribute at the element.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5022 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index c2a52fe..f1c6612 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,32 @@
+2003-09-20  Darin Adler  <darin at apple.com>
+
+        Reviewed by Dave.
+
+        - more fixes for the W3C DOM tests
+
+        * khtml/dom/dom_doc.cpp: (Document::createAttributeNS): Check that the attribute name
+        is valid and throw INVALID_CHARACTER_ERR if not.
+
+        * khtml/dom/dom_element.cpp:
+        (Element::removeAttributeNode): Get the attribute name properly. The old code would always
+        get a 0, so this function would always fail.
+        (Element::setAttributeNS): Check that the attribute name is valid and throw
+        INVALID_CHARACTER_ERR if not.
+        (Element::setAttributeNodeNS): Remove redundant exception checks that are also done by
+        setNamedItem in the implementation. I had to change the implementation of one, so I decided
+        it was better not to have any duplication.
+
+        * khtml/xml/dom_docimpl.h: Added isValidName function.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::createHTMLElement): Check that the attribute name is valid and throw
+        INVALID_CHARACTER_ERR if not.
+        (DocumentImpl::isValidName): Added. Used to check for valid names.
+
+        * khtml/xml/dom_elementimpl.cpp:
+        (NamedAttrMapImpl::setNamedItem): Don't do the document check until after checking for
+        the "replace self" case. Otherwise we raise a spurious "in use" exception.
+        (NamedAttrMapImpl::addAttribute): Point the new attribute at the element.
+
 2003-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index c2a52fe..f1c6612 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,32 @@
+2003-09-20  Darin Adler  <darin at apple.com>
+
+        Reviewed by Dave.
+
+        - more fixes for the W3C DOM tests
+
+        * khtml/dom/dom_doc.cpp: (Document::createAttributeNS): Check that the attribute name
+        is valid and throw INVALID_CHARACTER_ERR if not.
+
+        * khtml/dom/dom_element.cpp:
+        (Element::removeAttributeNode): Get the attribute name properly. The old code would always
+        get a 0, so this function would always fail.
+        (Element::setAttributeNS): Check that the attribute name is valid and throw
+        INVALID_CHARACTER_ERR if not.
+        (Element::setAttributeNodeNS): Remove redundant exception checks that are also done by
+        setNamedItem in the implementation. I had to change the implementation of one, so I decided
+        it was better not to have any duplication.
+
+        * khtml/xml/dom_docimpl.h: Added isValidName function.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::createHTMLElement): Check that the attribute name is valid and throw
+        INVALID_CHARACTER_ERR if not.
+        (DocumentImpl::isValidName): Added. Used to check for valid names.
+
+        * khtml/xml/dom_elementimpl.cpp:
+        (NamedAttrMapImpl::setNamedItem): Don't do the document check until after checking for
+        the "replace self" case. Otherwise we raise a spurious "in use" exception.
+        (NamedAttrMapImpl::addAttribute): Point the new attribute at the element.
+
 2003-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebCore/khtml/dom/dom_doc.cpp b/WebCore/khtml/dom/dom_doc.cpp
index 2f0ff51..50342f9 100644
--- a/WebCore/khtml/dom/dom_doc.cpp
+++ b/WebCore/khtml/dom/dom_doc.cpp
@@ -294,7 +294,8 @@ Attr Document::createAttributeNS( const DOMString &namespaceURI, const DOMString
         localName.remove(0, colonpos+1);
     }
 
-    // ### check correctness of parameters
+    if (!DocumentImpl::isValidName(localName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR);
+    // ### check correctness of namespace, prefix?
 
     NodeImpl::Id id = static_cast<DocumentImpl*>(impl)->attrId(namespaceURI.implementation(), localName.implementation(), false /* allocate */);
     Attr r = static_cast<DocumentImpl*>(impl)->createAttribute(id);
diff --git a/WebCore/khtml/dom/dom_element.cpp b/WebCore/khtml/dom/dom_element.cpp
index 2c1eef0..5d141ab 100644
--- a/WebCore/khtml/dom/dom_element.cpp
+++ b/WebCore/khtml/dom/dom_element.cpp
@@ -175,8 +175,10 @@ Attr Element::removeAttributeNode( const Attr &oldAttr )
     if (impl->getDocument() != oldAttr.handle()->getDocument())
         throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
 
+    NodeImpl::Id attrName = static_cast<AttrImpl*>(oldAttr.handle())->attrImpl()->id();
+
     int exceptioncode = 0;
-    Attr r = static_cast<ElementImpl*>(impl)->attributes(true)->removeNamedItem(oldAttr.handle()->id(), exceptioncode);
+    Attr r = static_cast<ElementImpl*>(impl)->attributes(true)->removeNamedItem(attrName, exceptioncode);
     if ( exceptioncode )
         throw DOMException( exceptioncode );
     return r;
@@ -219,6 +221,7 @@ void Element::setAttributeNS( const DOMString &namespaceURI,
         localName.remove(0, colonpos+1);
         // ### extract and set new prefix
     }
+    if (!DocumentImpl::isValidName(localName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR);
     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
                                                     localName.implementation(), false /* allocate */);
     int exceptioncode = 0;
@@ -257,12 +260,8 @@ Attr Element::getAttributeNodeNS( const DOMString &namespaceURI,
 
 Attr Element::setAttributeNodeNS( const Attr &newAttr )
 {
-    if (!impl || newAttr.isNull())
+    if (!impl)
         throw DOMException(DOMException::NOT_FOUND_ERR);
-    if (impl->getDocument() != newAttr.handle()->getDocument())
-        throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
-    if (!newAttr.ownerElement().isNull())
-        throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR);
 
     int exceptioncode = 0;
     Attr r = static_cast<ElementImpl*>(impl)->attributes(false)->setNamedItem(newAttr.handle(), exceptioncode);
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index 66c373c..22c5fb9 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -587,6 +587,8 @@ unsigned short DocumentImpl::nodeType() const
 
 ElementImpl *DocumentImpl::createHTMLElement( const DOMString &name )
 {
+    if (!isValidName(name)) throw DOMException(DOMException::INVALID_CHARACTER_ERR);
+
     uint id = khtml::getTagID( name.string().lower().latin1(), name.string().length() );
 
     ElementImpl *n = 0;
@@ -2337,6 +2339,29 @@ void DocumentImpl::setDomain(const DOMString &newDomain, bool force /*=false*/)
     }
 }
 
+bool DocumentImpl::isValidName(const DOMString &name)
+{
+    static const char validFirstCharacter[] = "ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz";
+    static const char validSubsequentCharacter[] = "ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz0-9-_:.";
+    const unsigned length = name.length();
+    if (length == 0)
+        return false;
+    const QChar * const characters = name.unicode();
+    const char fc = characters[0];
+    if (!fc)
+        return false;
+    if (strchr(validFirstCharacter, fc) == 0)
+        return false;
+    for (unsigned i = 1; i < length; ++i) {
+        const char sc = characters[i];
+        if (!sc)
+            return false;
+        if (strchr(validSubsequentCharacter, sc) == 0)
+            return false;
+    }
+    return true;
+}
+
 #if APPLE_CHANGES
 
 void DocumentImpl::setDecoder(Decoder *decoder)
diff --git a/WebCore/khtml/xml/dom_docimpl.h b/WebCore/khtml/xml/dom_docimpl.h
index e3bc40f..12ef226 100644
--- a/WebCore/khtml/xml/dom_docimpl.h
+++ b/WebCore/khtml/xml/dom_docimpl.h
@@ -446,6 +446,11 @@ public:
     DOMString domain() const;
     void setDomain( const DOMString &newDomain, bool force = false ); // not part of the DOM
     
+    // The following implements the rule from HTML 4 for what valid names are.
+    // To get this right for all the XML cases, we probably have to improve this or move it
+    // and make it sensitive to the type of document.
+    static bool isValidName(const DOMString &);
+    
 signals:
     void finishedParsing();
 
diff --git a/WebCore/khtml/xml/dom_elementimpl.cpp b/WebCore/khtml/xml/dom_elementimpl.cpp
index 375e086..9b14ad2 100644
--- a/WebCore/khtml/xml/dom_elementimpl.cpp
+++ b/WebCore/khtml/xml/dom_elementimpl.cpp
@@ -595,6 +595,10 @@ Node NamedAttrMapImpl::setNamedItem ( NodeImpl* arg, int &exceptioncode )
     }
     AttrImpl *attr = static_cast<AttrImpl*>(arg);
 
+    AttributeImpl* a = attr->attrImpl();
+    AttributeImpl* old = getAttributeItem(a->id());
+    if (old == a) return arg; // we know about it already
+
     // INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object.
     // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
     if (attr->ownerElement()) {
@@ -602,10 +606,6 @@ Node NamedAttrMapImpl::setNamedItem ( NodeImpl* arg, int &exceptioncode )
         return 0;
     }
 
-    AttributeImpl* a = attr->attrImpl();
-    AttributeImpl* old = getAttributeItem(a->id());
-    if (old == a) return arg; // we know about it already
-
     // ### slightly inefficient - resizes attribute array twice.
     Node r;
     if (old) {
@@ -725,7 +725,7 @@ NamedAttrMapImpl& NamedAttrMapImpl::operator=(const NamedAttrMapImpl& other)
 
 void NamedAttrMapImpl::addAttribute(AttributeImpl *attr)
 {
-    // Add the attribute tot he list
+    // Add the attribute to the list
     AttributeImpl **newAttrs = new AttributeImpl* [len+1];
     if (attrs) {
       for (uint i = 0; i < len; i++)
@@ -736,6 +736,10 @@ void NamedAttrMapImpl::addAttribute(AttributeImpl *attr)
     attrs[len++] = attr;
     attr->ref();
 
+    AttrImpl * const attrImpl = attr->_impl;
+    if (attrImpl)
+        attrImpl->m_element = element;
+
     // Notify the element that the attribute has been added, and dispatch appropriate mutation events
     // Note that element may be null here if we are called from insertAttr() during parsing
     if (element) {

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list