From 527fb3fff577a9767f24bbb0696f9cfd71628afb Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 20 Apr 2017 17:37:07 +0300 Subject: [PATCH] Bug 1358104 - Only throw InvalidCharacterError for bad XML id's, not NamespaceError r=baku Discussion at . 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 --HG-- extra : rebase_source : 2f0051f48124380f17300a38ceb8c2ab23015ca1 --- dom/base/nsContentUtils.cpp | 7 +-- .../test_createAttributeNS01.html | 4 +- .../test_createDocument01.html | 4 +- .../test_createDocumentType01.html | 4 +- .../test_createElementNS01.html | 4 +- .../test_documentcreateattributeNS04.html | 2 +- ...est_domimplementationcreatedocument07.html | 2 +- .../test_setAttributeNS02.html | 4 +- .../DOMImplementation-createDocumentType.html | 6 +-- .../dom/nodes/Document-createElementNS.js | 48 +++++++++---------- .../tests/dom/nodes/attributes.html | 4 +- 11 files changed, 42 insertions(+), 47 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a35f546208d63..69d675ff80ac4 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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 diff --git a/dom/tests/mochitest/dom-level2-core/test_createAttributeNS01.html b/dom/tests/mochitest/dom-level2-core/test_createAttributeNS01.html index aea5a3a6e0cf5..727ee15f8caf9 100644 --- a/dom/tests/mochitest/dom-level2-core/test_createAttributeNS01.html +++ b/dom/tests/mochitest/dom-level2-core/test_createAttributeNS01.html @@ -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); } } diff --git a/dom/tests/mochitest/dom-level2-core/test_createDocument01.html b/dom/tests/mochitest/dom-level2-core/test_createDocument01.html index ffc032082893b..173c2bdb824b3 100644 --- a/dom/tests/mochitest/dom-level2-core/test_createDocument01.html +++ b/dom/tests/mochitest/dom-level2-core/test_createDocument01.html @@ -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); } } diff --git a/dom/tests/mochitest/dom-level2-core/test_createDocumentType01.html b/dom/tests/mochitest/dom-level2-core/test_createDocumentType01.html index d52ce64e1c44d..d6d460d009695 100644 --- a/dom/tests/mochitest/dom-level2-core/test_createDocumentType01.html +++ b/dom/tests/mochitest/dom-level2-core/test_createDocumentType01.html @@ -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); } } diff --git a/dom/tests/mochitest/dom-level2-core/test_createElementNS01.html b/dom/tests/mochitest/dom-level2-core/test_createElementNS01.html index e15464d3b42a7..e592d096fbd6e 100644 --- a/dom/tests/mochitest/dom-level2-core/test_createElementNS01.html +++ b/dom/tests/mochitest/dom-level2-core/test_createElementNS01.html @@ -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); } } diff --git a/dom/tests/mochitest/dom-level2-core/test_documentcreateattributeNS04.html b/dom/tests/mochitest/dom-level2-core/test_documentcreateattributeNS04.html index 89e34b874d300..1485f75a07bff 100644 --- a/dom/tests/mochitest/dom-level2-core/test_documentcreateattributeNS04.html +++ b/dom/tests/mochitest/dom-level2-core/test_documentcreateattributeNS04.html @@ -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); } diff --git a/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocument07.html b/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocument07.html index b87b2150cb872..056fa2d256ec6 100644 --- a/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocument07.html +++ b/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocument07.html @@ -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); } diff --git a/dom/tests/mochitest/dom-level2-core/test_setAttributeNS02.html b/dom/tests/mochitest/dom-level2-core/test_setAttributeNS02.html index 6f58738f6cf68..de73321e66b96 100644 --- a/dom/tests/mochitest/dom-level2-core/test_setAttributeNS02.html +++ b/dom/tests/mochitest/dom-level2-core/test_setAttributeNS02.html @@ -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); } } diff --git a/testing/web-platform/tests/dom/nodes/DOMImplementation-createDocumentType.html b/testing/web-platform/tests/dom/nodes/DOMImplementation-createDocumentType.html index ac79ddd7340a7..f7e6e18b84425 100644 --- a/testing/web-platform/tests/dom/nodes/DOMImplementation-createDocumentType.html +++ b/testing/web-platform/tests/dom/nodes/DOMImplementation-createDocumentType.html @@ -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], diff --git a/testing/web-platform/tests/dom/nodes/Document-createElementNS.js b/testing/web-platform/tests/dom/nodes/Document-createElementNS.js index 1abd3330183c1..bf5e12cf95181 100644 --- a/testing/web-platform/tests/dom/nodes/Document-createElementNS.js +++ b/testing/web-platform/tests/dom/nodes/Document-createElementNS.js @@ -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], @@ -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], @@ -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], @@ -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"], @@ -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], @@ -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], @@ -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"], @@ -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], diff --git a/testing/web-platform/tests/dom/nodes/attributes.html b/testing/web-platform/tests/dom/nodes/attributes.html index 8d983350df9df..d1f2aeea571f0 100644 --- a/testing/web-platform/tests/dom/nodes/attributes.html +++ b/testing/web-platform/tests/dom/nodes/attributes.html @@ -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() {