summaryrefslogtreecommitdiff
path: root/ext/dom/document.c
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2004-05-27 11:15:45 +0000
committerRob Richards <rrichards@php.net>2004-05-27 11:15:45 +0000
commitedae935c266fe883a0adeff005d843b70eb2ea66 (patch)
tree31bf44fac6441b22935cb0b71e9d45173f6c44b9 /ext/dom/document.c
parent7f887852a64875722f96eeb549b337f94500d739 (diff)
downloadphp-git-edae935c266fe883a0adeff005d843b70eb2ea66.tar.gz
namespace/tagname validation fixes (Adam Trachtenberg)
added new test
Diffstat (limited to 'ext/dom/document.c')
-rw-r--r--ext/dom/document.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 5dbfaa8f3c..0a2fbfa7be 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -759,8 +759,8 @@ PHP_FUNCTION(dom_document_create_element)
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (name_len == 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element name is required");
+ if (xmlValidateName((xmlChar *) name, 0) != 0) {
+ php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
RETURN_FALSE;
}
@@ -908,6 +908,11 @@ PHP_FUNCTION(dom_document_create_processing_instruction)
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
+ if (xmlValidateName((xmlChar *) name, 0) != 0) {
+ php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
@@ -939,8 +944,8 @@ PHP_FUNCTION(dom_document_create_attribute)
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (name_len == 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required");
+ if (xmlValidateName((xmlChar *) name, 0) != 0) {
+ php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
RETURN_FALSE;
}
@@ -974,6 +979,11 @@ PHP_FUNCTION(dom_document_create_entity_reference)
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
+ if (xmlValidateName((xmlChar *) name, 0) != 0) {
+ php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
node = xmlNewReference(docp, name);
if (!node) {
RETURN_FALSE;
@@ -1073,23 +1083,22 @@ PHP_FUNCTION(dom_document_create_element_ns)
return;
}
- if (name_len == 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element Name is required");
- RETURN_FALSE;
- }
-
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
if (errorcode == 0) {
- nodep = xmlNewDocNode (docp, NULL, localname, NULL);
- if (nodep != NULL && uri != NULL) {
- nsptr = xmlSearchNsByHref (nodep->doc, nodep, uri);
- if (nsptr == NULL) {
- nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
+ if (xmlValidateName((xmlChar *) localname, 0) == 0) {
+ nodep = xmlNewDocNode (docp, NULL, localname, NULL);
+ if (nodep != NULL && uri != NULL) {
+ nsptr = xmlSearchNsByHref (nodep->doc, nodep, uri);
+ if (nsptr == NULL) {
+ nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
+ }
+ xmlSetNs(nodep, nsptr);
}
- xmlSetNs(nodep, nsptr);
+ } else {
+ errorcode = INVALID_CHARACTER_ERR;
}
}
@@ -1138,24 +1147,23 @@ PHP_FUNCTION(dom_document_create_attribute_ns)
return;
}
- if (name_len == 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Qualified Name is required");
- RETURN_FALSE;
- }
-
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
root = xmlDocGetRootElement(docp);
if (root != NULL) {
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
if (errorcode == 0) {
- nodep = (xmlNodePtr) xmlNewDocProp(docp, localname, NULL);
- if (nodep != NULL && uri_len > 0) {
- nsptr = xmlSearchNsByHref (nodep->doc, root, uri);
- if (nsptr == NULL) {
- nsptr = dom_get_ns(root, uri, &errorcode, prefix);
+ if (xmlValidateName((xmlChar *) localname, 0) == 0) {
+ nodep = (xmlNodePtr) xmlNewDocProp(docp, localname, NULL);
+ if (nodep != NULL && uri_len > 0) {
+ nsptr = xmlSearchNsByHref (nodep->doc, root, uri);
+ if (nsptr == NULL) {
+ nsptr = dom_get_ns(root, uri, &errorcode, prefix);
+ }
+ xmlSetNs(nodep, nsptr);
}
- xmlSetNs(nodep, nsptr);
+ } else {
+ errorcode = INVALID_CHARACTER_ERR;
}
}
} else {