Skip to content

Commit

Permalink
Bug 1358104 - Only throw InvalidCharacterError for bad XML id's, not …
Browse files Browse the repository at this point in the history
…NamespaceError r=baku

Discussion at <whatwg/dom#319>.  In short, the
specification used to say to throw sometimes InvalidCharacterError and
sometimes NamespaceError, but browsers disagreed on which to throw in
corner cases, and everyone agreed it wasn't worth the effort to spec the
distinction, so we just changed it to InvalidCharacterError across the
board.

The test changes are already upstream.

MozReview-Commit-ID: AWSZBznQprG
  • Loading branch information
ayg committed Apr 20, 2017
1 parent bc2d30f commit f803e1d
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 47 deletions.
7 changes: 1 addition & 6 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3094,12 +3094,7 @@ nsContentUtils::CheckQName(const nsAString& aQualifiedName,
return NS_OK;
}

// MOZ_EXPAT_EMPTY_QNAME || MOZ_EXPAT_INVALID_CHARACTER
if (result == (1 << 0) || result == (1 << 1)) {
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}

return NS_ERROR_DOM_NAMESPACE_ERR;
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}

//static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
newAttr = doc.createAttributeNS(namespaceURI,malformedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("throw_NAMESPACE_ERR",success);
assertTrue("throw INVALID_CHARACTER_ERR",success);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@
aNewDoc = domImpl.createDocument(namespaceURI,malformedName,docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("throw_NAMESPACE_ERR",success);
assertTrue("throw INVALID_CHARACTER_ERR",success);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
newType = domImpl.createDocumentType(malformedName,publicId,systemId);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("throw_NAMESPACE_ERR",success);
assertTrue("throw INVALID_CHARACTER_ERR", success);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
newElement = doc.createElementNS(namespaceURI,malformedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("throw_NAMESPACE_ERR",success);
assertTrue("throw INVALID_CHARACTER_ERR", success);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
attribute = doc.createAttributeNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("documentcreateattributeNS04",success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
newDoc = domImpl.createDocument(namespaceURI,":",docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("domimplementationcreatedocument07",success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
testAddr.setAttributeNS(namespaceURI,qualifiedName,"newValue");
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
success = ex.code === DOMException.INVALID_CHARACTER_ERR;
}
assertTrue("throw_NAMESPACE_ERR",success);
assertTrue("throw INVALID_CHARACTER_ERR",success);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
["(", "", "", "INVALID_CHARACTER_ERR"],
[")", "", "", "INVALID_CHARACTER_ERR"],
["f:oo", "", "", null],
[":foo", "", "", "NAMESPACE_ERR"],
["foo:", "", "", "NAMESPACE_ERR"],
["prefix::local", "", "", "NAMESPACE_ERR"],
[":foo", "", "", "INVALID_CHARACTER_ERR"],
["foo:", "", "", "INVALID_CHARACTER_ERR"],
["prefix::local", "", "", "INVALID_CHARACTER_ERR"],
["foo", "foo", "", null],
["foo", "", "foo", null],
["foo", "f'oo", "", null],
Expand Down
48 changes: 24 additions & 24 deletions testing/web-platform/tests/dom/nodes/Document-createElementNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ var createElementNS_tests = [
[null, "fo o", "INVALID_CHARACTER_ERR"],
[null, "-foo", "INVALID_CHARACTER_ERR"],
[null, ".foo", "INVALID_CHARACTER_ERR"],
[null, ":foo", "NAMESPACE_ERR"],
[null, ":foo", "INVALID_CHARACTER_ERR"],
[null, "f:oo", "NAMESPACE_ERR"],
[null, "foo:", "NAMESPACE_ERR"],
[null, "f:o:o", "NAMESPACE_ERR"],
[null, ":", "NAMESPACE_ERR"],
[null, "foo:", "INVALID_CHARACTER_ERR"],
[null, "f:o:o", "INVALID_CHARACTER_ERR"],
[null, ":", "INVALID_CHARACTER_ERR"],
[null, "xml", null],
[null, "xmlns", "NAMESPACE_ERR"],
[null, "xmlfoo", null],
Expand All @@ -38,19 +38,19 @@ var createElementNS_tests = [
[null, "xmlfoo:bar", "NAMESPACE_ERR"],
[null, "null:xml", "NAMESPACE_ERR"],
["", null, null],
["", ":foo", "NAMESPACE_ERR"],
["", ":foo", "INVALID_CHARACTER_ERR"],
["", "f:oo", "NAMESPACE_ERR"],
["", "foo:", "NAMESPACE_ERR"],
["", "foo:", "INVALID_CHARACTER_ERR"],
[undefined, null, null],
[undefined, undefined, null],
[undefined, "foo", null],
[undefined, "1foo", "INVALID_CHARACTER_ERR"],
[undefined, "f1oo", null],
[undefined, "foo1", null],
[undefined, ":foo", "NAMESPACE_ERR"],
[undefined, ":foo", "INVALID_CHARACTER_ERR"],
[undefined, "f:oo", "NAMESPACE_ERR"],
[undefined, "foo:", "NAMESPACE_ERR"],
[undefined, "f::oo", "NAMESPACE_ERR"],
[undefined, "foo:", "INVALID_CHARACTER_ERR"],
[undefined, "f::oo", "INVALID_CHARACTER_ERR"],
[undefined, "xml", null],
[undefined, "xmlns", "NAMESPACE_ERR"],
[undefined, "xmlfoo", null],
Expand All @@ -65,15 +65,15 @@ var createElementNS_tests = [
["http://example.com/", ".foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f1oo", null],
["http://example.com/", "foo1", null],
["http://example.com/", ":foo", "NAMESPACE_ERR"],
["http://example.com/", ":foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f:oo", null],
["http://example.com/", "f:o:o", "NAMESPACE_ERR"],
["http://example.com/", "foo:", "NAMESPACE_ERR"],
["http://example.com/", "f::oo", "NAMESPACE_ERR"],
["http://example.com/", "a:0", "NAMESPACE_ERR"],
["http://example.com/", "f:o:o", "INVALID_CHARACTER_ERR"],
["http://example.com/", "foo:", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f::oo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:0", "INVALID_CHARACTER_ERR"],
["http://example.com/", "0:a", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:_", null],
["http://example.com/", "a:\u0BC6", "NAMESPACE_ERR"],
["http://example.com/", "a:\u0BC6", "INVALID_CHARACTER_ERR"],
["http://example.com/", "\u0BC6:a", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:a\u0BC6", null],
["http://example.com/", "a\u0BC6:a", null],
Expand All @@ -98,7 +98,7 @@ var createElementNS_tests = [
["http://example.com/", "xmlns:foo", "NAMESPACE_ERR"],
["http://example.com/", "XMLNS:foo", null],
["http://example.com/", "xmlfoo:bar", null],
["http://example.com/", "prefix::local", "NAMESPACE_ERR"],
["http://example.com/", "prefix::local", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:{", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:}", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:~", "INVALID_CHARACTER_ERR"],
Expand Down Expand Up @@ -130,9 +130,9 @@ var createElementNS_tests = [
["/", "1foo", "INVALID_CHARACTER_ERR"],
["/", "f1oo", null],
["/", "foo1", null],
["/", ":foo", "NAMESPACE_ERR"],
["/", ":foo", "INVALID_CHARACTER_ERR"],
["/", "f:oo", null],
["/", "foo:", "NAMESPACE_ERR"],
["/", "foo:", "INVALID_CHARACTER_ERR"],
["/", "xml", null],
["/", "xmlns", "NAMESPACE_ERR"],
["/", "xmlfoo", null],
Expand All @@ -143,9 +143,9 @@ var createElementNS_tests = [
["http://www.w3.org/XML/1998/namespace", "1foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "f1oo", null],
["http://www.w3.org/XML/1998/namespace", "foo1", null],
["http://www.w3.org/XML/1998/namespace", ":foo", "NAMESPACE_ERR"],
["http://www.w3.org/XML/1998/namespace", ":foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "f:oo", null],
["http://www.w3.org/XML/1998/namespace", "foo:", "NAMESPACE_ERR"],
["http://www.w3.org/XML/1998/namespace", "foo:", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "xml", null],
["http://www.w3.org/XML/1998/namespace", "xmlns", "NAMESPACE_ERR"],
["http://www.w3.org/XML/1998/namespace", "xmlfoo", null],
Expand All @@ -158,9 +158,9 @@ var createElementNS_tests = [
["http://www.w3.org/2000/xmlns/", "1foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "f1oo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo1", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", ":foo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", ":foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "f:oo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo:", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo:", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "xml", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "xmlns", null],
["http://www.w3.org/2000/xmlns/", "xmlfoo", "NAMESPACE_ERR"],
Expand All @@ -172,9 +172,9 @@ var createElementNS_tests = [
["foo:", "1foo", "INVALID_CHARACTER_ERR"],
["foo:", "f1oo", null],
["foo:", "foo1", null],
["foo:", ":foo", "NAMESPACE_ERR"],
["foo:", ":foo", "INVALID_CHARACTER_ERR"],
["foo:", "f:oo", null],
["foo:", "foo:", "NAMESPACE_ERR"],
["foo:", "foo:", "INVALID_CHARACTER_ERR"],
["foo:", "xml", null],
["foo:", "xmlns", "NAMESPACE_ERR"],
["foo:", "xmlfoo", null],
Expand Down
4 changes: 2 additions & 2 deletions testing/web-platform/tests/dom/nodes/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@
test(function() {
var el = document.createElement("foo")
for (var i = 0, il = invalid_qnames.length; i < il; ++i) {
assert_throws("NAMESPACE_ERR",
assert_throws("INVALID_CHARACTER_ERR",
function() { el.setAttributeNS("a", invalid_qnames[i], "fail") },
"Expected exception for " + invalid_qnames[i] + ".")
}
}, "When qualifiedName does not match the QName production, an " +
"NAMESPACE_ERR exception is to be thrown.")
"INVALID_CHARACTER_ERR exception is to be thrown.")

// Step 3
test(function() {
Expand Down

0 comments on commit f803e1d

Please sign in to comment.