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
+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.
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
{ 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
];
+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.
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;
}
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
return 0;
QualifiedName qName(prefix, localName, namespaceURI);
- if (hasPrefixNamespaceMismatch(qName)) {
+ if (!hasValidNamespaceForElements(qName)) {
ec = NAMESPACE_ERR;
return 0;
}
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;
}
// 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&);
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;
}