From df84e73e91ae50e2fa8f2c3cd4ca264b6f4052cf Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 2 Nov 2012 20:39:42 +0000 Subject: Disable validation of element and attribute names in HTML DOM trees --- src/html/html_document.c | 87 +++++++++++++++++++--- src/html/html_document.h | 9 ++- ...entinvalidcharacterexceptioncreateattribute.xml | 44 ----------- ...acterexceptioncreateattribute.xml.not-for-html5 | 44 +++++++++++ ...ntinvalidcharacterexceptioncreateattribute1.xml | 36 --------- ...cterexceptioncreateattribute1.xml.not-for-html5 | 36 +++++++++ ...umentinvalidcharacterexceptioncreateelement.xml | 44 ----------- ...aracterexceptioncreateelement.xml.not-for-html5 | 44 +++++++++++ ...mentinvalidcharacterexceptioncreateelement1.xml | 36 --------- ...racterexceptioncreateelement1.xml.not-for-html5 | 36 +++++++++ 10 files changed, 242 insertions(+), 174 deletions(-) delete mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml create mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml.not-for-html5 delete mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml create mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml.not-for-html5 delete mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml create mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml.not-for-html5 delete mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml create mode 100644 test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml.not-for-html5 diff --git a/src/html/html_document.c b/src/html/html_document.c index a27fcaa..cec4526 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -25,10 +25,10 @@ #include "html/html_option_element.h" #include "html/html_select_element.h" +#include "core/attr.h" #include "core/string.h" #include "utils/namespace.h" #include "utils/utils.h" -#include "utils/validate.h" static struct dom_html_document_vtable html_document_vtable = { { @@ -233,9 +233,6 @@ dom_exception _dom_html_document_create_element(dom_document *doc, { dom_html_document *html = (dom_html_document *) doc; - if (_dom_validate_name(tag_name) == false) - return DOM_INVALID_CHARACTER_ERR; - return _dom_html_document_create_element_internal(html, tag_name, NULL, NULL, (dom_html_element **)result); @@ -249,24 +246,90 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc, dom_string *prefix, *localname; dom_exception err; - if (_dom_validate_name(qname) == false) - return DOM_INVALID_CHARACTER_ERR; - - /* Validate qname */ - err = _dom_namespace_validate_qname(qname, namespace); + /* Divide QName into prefix/localname pair */ + err = _dom_namespace_split_qname(qname, &prefix, &localname); if (err != DOM_NO_ERR) { return err; } + /* Attempt to create element */ + err = _dom_html_document_create_element_internal(html, localname, + namespace, prefix, (dom_html_element **)result); + + /* Tidy up */ + if (localname != NULL) { + dom_string_unref(localname); + } + + if (prefix != NULL) { + dom_string_unref(prefix); + } + + return err; +} + +/** + * Create an attribute + * + * \param doc The document owning the attribute + * \param name The name of the attribute + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * + * The constructed attribute will always be classified as 'specified'. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception _dom_html_document_create_attribute(dom_document *doc, + dom_string *name, dom_attr **result) +{ + return _dom_attr_create(doc, name, NULL, NULL, true, result); +} + +/** + * Create an attribute from the qualified name and namespace URI + * + * \param doc The document owning the attribute + * \param namespace The namespace URI to use + * \param qname The qualified name of the attribute + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_NAMESPACE_ERR if ::qname is malformed, or it has a + * prefix and ::namespace is NULL, or + * ::qname has a prefix "xml" and + * ::namespace is not + * "http://www.w3.org/XML/1998/namespace", + * or ::qname has a prefix "xmlns" and + * ::namespace is not + * "http://www.w3.org/2000/xmlns", or + * ::namespace is + * "http://www.w3.org/2000/xmlns" and + * ::qname is not (or is not prefixed by) + * "xmlns", + * DOM_NOT_SUPPORTED_ERR if ::doc does not support the "XML" + * feature. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception _dom_html_document_create_attribute_ns(dom_document *doc, + dom_string *namespace, dom_string *qname, + dom_attr **result) +{ + dom_string *prefix, *localname; + dom_exception err; + /* Divide QName into prefix/localname pair */ err = _dom_namespace_split_qname(qname, &prefix, &localname); if (err != DOM_NO_ERR) { return err; } - /* Attempt to create element */ - err = _dom_html_document_create_element_internal(html, localname, - namespace, prefix, (dom_html_element **)result); + /* Attempt to create attribute */ + err = _dom_attr_create(doc, localname, namespace, prefix, true, result); /* Tidy up */ if (localname != NULL) { diff --git a/src/html/html_document.h b/src/html/html_document.h index bb1a0d2..ecc6236 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -118,6 +118,11 @@ dom_exception _dom_html_document_get_elements_by_tag_name(dom_document *doc, dom_exception _dom_html_document_get_elements_by_tag_name_ns( dom_document *doc, dom_string *namespace, dom_string *localname, dom_nodelist **result); +dom_exception _dom_html_document_create_attribute(dom_document *doc, + dom_string *name, dom_attr **result); +dom_exception _dom_html_document_create_attribute_ns(dom_document *doc, + dom_string *namespace, dom_string *qname, + dom_attr **result); #define DOM_DOCUMENT_VTABLE_HTML \ _dom_document_get_doctype, \ @@ -129,12 +134,12 @@ dom_exception _dom_html_document_get_elements_by_tag_name_ns( _dom_document_create_comment, \ _dom_document_create_cdata_section, \ _dom_document_create_processing_instruction, \ - _dom_document_create_attribute, \ + _dom_html_document_create_attribute, \ _dom_document_create_entity_reference, \ _dom_html_document_get_elements_by_tag_name, \ _dom_document_import_node, \ _dom_html_document_create_element_ns, \ - _dom_document_create_attribute_ns, \ + _dom_html_document_create_attribute_ns, \ _dom_html_document_get_elements_by_tag_name_ns, \ _dom_document_get_element_by_id, \ _dom_document_get_input_encoding, \ diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml deleted file mode 100644 index 0a73b4e..0000000 --- a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - -hc_documentInvalidCharacterExceptionCreateAttribute -Curt Arnold - - The "createAttribute(tagName)" method raises an - INVALID_CHARACTER_ERR DOMException if the specified - tagName contains an invalid character. - - Retrieve the entire DOM document and invoke its - "createAttribute(tagName)" method with the tagName equal - to the string "invalid^Name". Due to the invalid - character the desired EXCEPTION should be raised. - - -2002-06-09 - - - - - - - - - - - - - - - diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml.not-for-html5 b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml.not-for-html5 new file mode 100644 index 0000000..0a73b4e --- /dev/null +++ b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute.xml.not-for-html5 @@ -0,0 +1,44 @@ + + + + + +hc_documentInvalidCharacterExceptionCreateAttribute +Curt Arnold + + The "createAttribute(tagName)" method raises an + INVALID_CHARACTER_ERR DOMException if the specified + tagName contains an invalid character. + + Retrieve the entire DOM document and invoke its + "createAttribute(tagName)" method with the tagName equal + to the string "invalid^Name". Due to the invalid + character the desired EXCEPTION should be raised. + + +2002-06-09 + + + + + + + + + + + + + + + diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml deleted file mode 100644 index e9b70f8..0000000 --- a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - -hc_documentinvalidcharacterexceptioncreateattribute1 -Curt Arnold - -Creating an attribute with an empty name should cause an INVALID_CHARACTER_ERR. - -2004-03-09 - - - - - - - - - - - - - - - diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml.not-for-html5 b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml.not-for-html5 new file mode 100644 index 0000000..e9b70f8 --- /dev/null +++ b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1.xml.not-for-html5 @@ -0,0 +1,36 @@ + + + + + +hc_documentinvalidcharacterexceptioncreateattribute1 +Curt Arnold + +Creating an attribute with an empty name should cause an INVALID_CHARACTER_ERR. + +2004-03-09 + + + + + + + + + + + + + + + diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml deleted file mode 100644 index 9adca61..0000000 --- a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - -hc_documentInvalidCharacterExceptionCreateElement -Curt Arnold - - The "createElement(tagName)" method raises an - INVALID_CHARACTER_ERR DOMException if the specified - tagName contains an invalid character. - - Retrieve the entire DOM document and invoke its - "createElement(tagName)" method with the tagName equal - to the string "invalid^Name". Due to the invalid - character the desired EXCEPTION should be raised. - - -2002-06-09 - - - - - - - - - - - - - - - diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml.not-for-html5 b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml.not-for-html5 new file mode 100644 index 0000000..9adca61 --- /dev/null +++ b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement.xml.not-for-html5 @@ -0,0 +1,44 @@ + + + + + +hc_documentInvalidCharacterExceptionCreateElement +Curt Arnold + + The "createElement(tagName)" method raises an + INVALID_CHARACTER_ERR DOMException if the specified + tagName contains an invalid character. + + Retrieve the entire DOM document and invoke its + "createElement(tagName)" method with the tagName equal + to the string "invalid^Name". Due to the invalid + character the desired EXCEPTION should be raised. + + +2002-06-09 + + + + + + + + + + + + + + + diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml deleted file mode 100644 index 3f0bc53..0000000 --- a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - -hc_documentinvalidcharacterexceptioncreateelement1 -Curt Arnold - -Creating an element with an empty name should cause an INVALID_CHARACTER_ERR. - -2004-03-09 - - - - - - - - - - - - - - - diff --git a/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml.not-for-html5 b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml.not-for-html5 new file mode 100644 index 0000000..3f0bc53 --- /dev/null +++ b/test/testcases/tests/level1/core/hc_documentinvalidcharacterexceptioncreateelement1.xml.not-for-html5 @@ -0,0 +1,36 @@ + + + + + +hc_documentinvalidcharacterexceptioncreateelement1 +Curt Arnold + +Creating an element with an empty name should cause an INVALID_CHARACTER_ERR. + +2004-03-09 + + + + + + + + + + + + + + + -- cgit v1.2.3