createAttributeNS should understand that "xmlns" is allowed in the http://www.w3...
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 08:31:13 +0000 (08:31 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 08:31:13 +0000 (08:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76579

Reviewed by Eric Seidel.

Source/WebCore:

This patch cleans up a tiny corner case involving the (somewhat
magical) xmlns attribute that we uncovered when working on
setAttributeNS.

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

* dom/Document.cpp:
(WebCore::Document::importNode):
(WebCore::Document::hasValidNamespaceForElements):
(WebCore::Document::hasValidNamespaceForAttributes):
(WebCore::Document::createElementNS):
(WebCore::Document::createAttributeNS):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::setAttributeNS):

LayoutTests:

* fast/dom/Document/createAttributeNS-namespace-err-expected.txt:
* fast/dom/Document/script-tests/createAttributeNS-namespace-err.js:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105391 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/Document/createAttributeNS-namespace-err-expected.txt
LayoutTests/fast/dom/Document/script-tests/createAttributeNS-namespace-err.js
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp

index 63828e6..7471897 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-19  Adam Barth  <abarth@webkit.org>
+
+        createAttributeNS should understand that "xmlns" is allowed in the http://www.w3.org/2000/xmlns/
+        https://bugs.webkit.org/show_bug.cgi?id=76579
+
+        Reviewed by Eric Seidel.
+
+        * fast/dom/Document/createAttributeNS-namespace-err-expected.txt:
+        * fast/dom/Document/script-tests/createAttributeNS-namespace-err.js:
+
 2012-01-18  Shinya Kawanaka  <shinyak@google.com>
 
         ShadowContent query should be able to have fallback elements.
index f02ca55..9f97776 100644 (file)
@@ -45,6 +45,7 @@ PASS createAttributeNS("http://www.w3.org/2000/xmlns/", "x:test"); binding names
 PASS createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:test")
 PASS createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:test")
 PASS createAttributeNS("http://www.w3.org/XML/1998/namespace", "x:test")
+PASS createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns")
 PASS createAttributeNS("http://example.com/", "xmlns"); threw NAMESPACE_ERR
 PASS successfullyParsed is true
 
index ddeeb71..26cdd2a 100644 (file)
@@ -82,6 +82,7 @@ var allNSTests = [
    { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
    { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
    { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
+   { args: ["http://www.w3.org/2000/xmlns/", "xmlns"] }, // See http://www.w3.org/2000/xmlns/
    { args: ["http://example.com/", "xmlns"], code: 14 }, // from the createAttributeNS section
 ];
 
index d936543..53de2f1 100644 (file)
@@ -1,3 +1,26 @@
+2012-01-19  Adam Barth  <abarth@webkit.org>
+
+        createAttributeNS should understand that "xmlns" is allowed in the http://www.w3.org/2000/xmlns/
+        https://bugs.webkit.org/show_bug.cgi?id=76579
+
+        Reviewed by Eric Seidel.
+
+        This patch cleans up a tiny corner case involving the (somewhat
+        magical) xmlns attribute that we uncovered when working on
+        setAttributeNS.
+
+        Tests: fast/dom/Document/createAttributeNS-namespace-err.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::importNode):
+        (WebCore::Document::hasValidNamespaceForElements):
+        (WebCore::Document::hasValidNamespaceForAttributes):
+        (WebCore::Document::createElementNS):
+        (WebCore::Document::createAttributeNS):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::setAttributeNS):
+
 2012-01-19  Roland Steiner  <rolandsteiner@chromium.org>
 
         Unreviewed build fix for DEBUG: remove comparison of an unsigned variable with '>= 0' in ASSERT.
index aa2f449..c596bdd 100644 (file)
@@ -833,7 +833,7 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo
         Element* oldElement = static_cast<Element*>(importedNode);
         // FIXME: The following check might be unnecessary. Is it possible that
         // oldElement has mismatched prefix/namespace?
-        if (hasPrefixNamespaceMismatch(oldElement->tagQName())) {
+        if (!hasValidNamespaceForElements(oldElement->tagQName())) {
             ec = NAMESPACE_ERR;
             return 0;
         }
@@ -948,22 +948,33 @@ PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionCode& ec)
     return source;
 }
 
-bool Document::hasPrefixNamespaceMismatch(const QualifiedName& qName)
+bool Document::hasValidNamespaceForElements(const QualifiedName& qName)
 {
     // These checks are from DOM Core Level 2, createElementNS
     // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS
     if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div")
-        return true;
+        return false;
     if (qName.prefix() == xmlAtom && qName.namespaceURI() != XMLNames::xmlNamespaceURI) // createElementNS("http://www.example.com", "xml:lang")
-        return true;
+        return false;
 
     // Required by DOM Level 3 Core and unspecified by DOM Level 2 Core:
     // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
     // createElementNS("http://www.w3.org/2000/xmlns/", "foo:bar"), createElementNS(null, "xmlns:bar")
     if ((qName.prefix() == xmlnsAtom && qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI) || (qName.prefix() != xmlnsAtom && qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI))
-        return true;
+        return false;
 
-    return false;
+    return true;
+}
+
+bool Document::hasValidNamespaceForAttributes(const QualifiedName& qName)
+{
+    // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAttrNS
+    if (qName.prefix().isEmpty() && qName.localName() == xmlnsAtom) {
+        // Note: The case of an "xmlns" qualified name with a namespace of
+        // xmlnsNamespaceURI is specifically allowed (See <http://www.w3.org/2000/xmlns/>).
+        return qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI;
+    }
+    return hasValidNamespaceForElements(qName);
 }
 
 // FIXME: This should really be in a possible ElementFactory class
@@ -1010,7 +1021,7 @@ PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const
         return 0;
 
     QualifiedName qName(prefix, localName, namespaceURI);
-    if (hasPrefixNamespaceMismatch(qName)) {
+    if (!hasValidNamespaceForElements(qName)) {
         ec = NAMESPACE_ERR;
         return 0;
     }
@@ -4287,13 +4298,8 @@ PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S
         return 0;
 
     QualifiedName qName(prefix, localName, namespaceURI);
-    if (!shouldIgnoreNamespaceChecks && hasPrefixNamespaceMismatch(qName)) {
-        ec = NAMESPACE_ERR;
-        return 0;
-    }
 
-    // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrAttrNS
-    if (!shouldIgnoreNamespaceChecks && qName.localName() == xmlnsAtom && qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI) {
+    if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) {
         ec = NAMESPACE_ERR;
         return 0;
     }
index 910f710..fdb3988 100644 (file)
@@ -856,10 +856,11 @@ public:
     // It also does a validity check, and returns false if the qualified name
     // is invalid.  It also sets ExceptionCode when name is invalid.
     static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
-    
+
     // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
-    static bool hasPrefixNamespaceMismatch(const QualifiedName&);
-    
+    static bool hasValidNamespaceForElements(const QualifiedName&);
+    static bool hasValidNamespaceForAttributes(const QualifiedName&);
+
     HTMLElement* body() const;
     void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
 
index 86896a7..37fb7a0 100644 (file)
@@ -1448,16 +1448,7 @@ void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicStrin
 
     QualifiedName qName(prefix, localName, namespaceURI);
 
-    // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAttrNS
-    if (qName.prefix().isEmpty() && qName.localName() == xmlnsAtom) {
-        if (qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI) {
-            ec = NAMESPACE_ERR;
-            return;
-        }
-        // Note: The case of an "xmlns" qualified name with a namespace of
-        // xmlnsNamespaceURI is specifically allowed (See
-        // <http://www.w3.org/2000/xmlns/>).
-    } else if (document()->hasPrefixNamespaceMismatch(qName)) {
+    if (!Document::hasValidNamespaceForAttributes(qName)) {
         ec = NAMESPACE_ERR;
         return;
     }