diff options
Diffstat (limited to 'ext/dom')
| -rw-r--r-- | ext/dom/attr.c | 4 | ||||
| -rw-r--r-- | ext/dom/dom_iterators.c | 24 | ||||
| -rw-r--r-- | ext/dom/domimplementation.c | 8 | ||||
| -rw-r--r-- | ext/dom/element.c | 4 | ||||
| -rw-r--r-- | ext/dom/namednodemap.c | 56 | ||||
| -rw-r--r-- | ext/dom/node.c | 4 | ||||
| -rw-r--r-- | ext/dom/notation.c | 16 | ||||
| -rw-r--r-- | ext/dom/php_dom.c | 18 | ||||
| -rw-r--r-- | ext/dom/tests/bug36756.phpt | 35 | ||||
| -rw-r--r-- | ext/dom/tests/bug37277.phpt | 25 | ||||
| -rw-r--r-- | ext/dom/tests/dom007.phpt | 99 |
11 files changed, 237 insertions, 56 deletions
diff --git a/ext/dom/attr.c b/ext/dom/attr.c index 75121b0a6..7d1642e62 100644 --- a/ext/dom/attr.c +++ b/ext/dom/attr.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: attr.c,v 1.18.2.1 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: attr.c,v 1.18.2.2 2006/05/03 08:43:04 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -77,7 +77,7 @@ PHP_METHOD(domattr, __construct) } if (intern != NULL) { - oldnode = (xmlNodePtr)intern->ptr; + oldnode = dom_object_get_node(intern); if (oldnode != NULL) { php_libxml_node_free_resource(oldnode TSRMLS_CC); } diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c index ef01536c7..862da4dc7 100644 --- a/ext/dom/dom_iterators.c +++ b/ext/dom/dom_iterators.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dom_iterators.c,v 1.9.2.2 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: dom_iterators.c,v 1.9.2.3 2006/03/03 20:15:10 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -200,7 +200,8 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC) curobj = iterator->curobj; intern = (dom_object *)zend_object_store_get_object(curobj TSRMLS_CC); if (intern != NULL && intern->ptr != NULL) { - if (objmap->ht == NULL) { + if (objmap->nodetype != XML_ENTITY_NODE && + objmap->nodetype != XML_NOTATION_NODE) { if (objmap->nodetype == DOM_NODESET) { nodeht = HASH_OF(objmap->baseobjptr); zend_hash_move_forward(nodeht); @@ -210,12 +211,14 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC) } } else { curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node; - if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { + if (objmap->nodetype == XML_ATTRIBUTE_NODE || + objmap->nodetype == XML_ELEMENT_NODE) { curnode = curnode->next; } else { /* Nav the tree evey time as this is LIVE */ basenode = dom_object_get_node(objmap->baseobj); - if (basenode && (basenode->type == XML_DOCUMENT_NODE || basenode->type == XML_HTML_DOCUMENT_NODE)) { + if (basenode && (basenode->type == XML_DOCUMENT_NODE || + basenode->type == XML_HTML_DOCUMENT_NODE)) { basenode = xmlDocGetRootElement((xmlDoc *) basenode); } else { basenode = basenode->children; @@ -225,9 +228,9 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC) } } else { if (objmap->nodetype == XML_ENTITY_NODE) { - curnode = php_dom_libxml_hash_iter(objmap->ht, iter->index); + curnode = php_dom_libxml_hash_iter(objmap->ht, iter->index - 1); } else { - curnode = php_dom_libxml_notation_iter(objmap->ht, iter->index); + curnode = php_dom_libxml_notation_iter(objmap->ht, iter->index - 1); } } } @@ -269,7 +272,8 @@ zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object TS intern = (dom_object *)zend_object_store_get_object(object TSRMLS_CC); objmap = (dom_nnodemap_object *)intern->ptr; if (objmap != NULL) { - if (objmap->ht == NULL) { + if (objmap->nodetype != XML_ENTITY_NODE && + objmap->nodetype != XML_NOTATION_NODE) { if (objmap->nodetype == DOM_NODESET) { nodeht = HASH_OF(objmap->baseobjptr); zend_hash_internal_pointer_reset(nodeht); @@ -295,7 +299,11 @@ zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object TS } } } else { - curnode = php_dom_libxml_hash_iter(objmap->ht, 0); + if (objmap->nodetype == XML_ENTITY_NODE) { + curnode = php_dom_libxml_hash_iter(objmap->ht, 0); + } else { + curnode = php_dom_libxml_notation_iter(objmap->ht, 0); + } } } diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c index 02c9d1e40..66adb568a 100644 --- a/ext/dom/domimplementation.c +++ b/ext/dom/domimplementation.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: domimplementation.c,v 1.15.2.1 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: domimplementation.c,v 1.15.2.2 2006/02/24 10:19:54 mike Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -92,7 +92,7 @@ PHP_METHOD(domimplementation, createDocumentType) pch2 = systemid; uri = xmlParseURI(name); - if (uri->opaque != NULL) { + if (uri != NULL && uri->opaque != NULL) { localname = xmlStrdup(uri->opaque); if (xmlStrchr(localname, (xmlChar) ':') != NULL) { php_dom_throw_error(NAMESPACE_ERR, 1 TSRMLS_CC); @@ -108,7 +108,9 @@ PHP_METHOD(domimplementation, createDocumentType) php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC); */ - xmlFreeURI(uri); + if (uri) { + xmlFreeURI(uri); + } doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2); xmlFree(localname); diff --git a/ext/dom/element.c b/ext/dom/element.c index d021d5aba..2be0e8f31 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: element.c,v 1.36.2.3 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: element.c,v 1.36.2.4 2006/05/03 08:43:04 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -128,7 +128,7 @@ PHP_METHOD(domelement, __construct) intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC); if (intern != NULL) { - oldnode = (xmlNodePtr)intern->ptr; + oldnode = dom_object_get_node(intern); if (oldnode != NULL) { php_libxml_node_free_resource(oldnode TSRMLS_CC); } diff --git a/ext/dom/namednodemap.c b/ext/dom/namednodemap.c index 92573fafa..478a4c40b 100644 --- a/ext/dom/namednodemap.c +++ b/ext/dom/namednodemap.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: namednodemap.c,v 1.15.2.1 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: namednodemap.c,v 1.15.2.2 2006/03/03 20:15:10 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -61,8 +61,11 @@ int dom_namednodemap_length_read(dom_object *obj, zval **retval TSRMLS_DC) objmap = (dom_nnodemap_object *)obj->ptr; if (objmap != NULL) { - if (objmap->ht) { - count = xmlHashSize(objmap->ht); + if ((objmap->nodetype == XML_NOTATION_NODE) || + objmap->nodetype == XML_ENTITY_NODE) { + if (objmap->ht) { + count = xmlHashSize(objmap->ht); + } } else { nodep = dom_object_get_node(objmap->baseobj); if (nodep) { @@ -113,12 +116,17 @@ PHP_FUNCTION(dom_namednodemap_get_named_item) objmap = (dom_nnodemap_object *)intern->ptr; if (objmap != NULL) { - if (objmap->ht) { - if (objmap->nodetype == XML_ENTITY_NODE) { - itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named); - } else { - notep = (xmlNotation *)xmlHashLookup(objmap->ht, named); - itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID); + if ((objmap->nodetype == XML_NOTATION_NODE) || + objmap->nodetype == XML_ENTITY_NODE) { + if (objmap->ht) { + if (objmap->nodetype == XML_ENTITY_NODE) { + itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named); + } else { + notep = (xmlNotation *)xmlHashLookup(objmap->ht, named); + if (notep) { + itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID); + } + } } } else { nodep = dom_object_get_node(objmap->baseobj); @@ -185,11 +193,14 @@ PHP_FUNCTION(dom_namednodemap_item) objmap = (dom_nnodemap_object *)intern->ptr; if (objmap != NULL) { - if (objmap->ht) { - if (objmap->nodetype == XML_ENTITY_NODE) { - itemnode = php_dom_libxml_hash_iter(objmap->ht, index); - } else { - itemnode = php_dom_libxml_notation_iter(objmap->ht, index); + if ((objmap->nodetype == XML_NOTATION_NODE) || + objmap->nodetype == XML_ENTITY_NODE) { + if (objmap->ht) { + if (objmap->nodetype == XML_ENTITY_NODE) { + itemnode = php_dom_libxml_hash_iter(objmap->ht, index); + } else { + itemnode = php_dom_libxml_notation_iter(objmap->ht, index); + } } } else { nodep = dom_object_get_node(objmap->baseobj); @@ -241,12 +252,17 @@ PHP_FUNCTION(dom_namednodemap_get_named_item_ns) objmap = (dom_nnodemap_object *)intern->ptr; if (objmap != NULL) { - if (objmap->ht) { - if (objmap->nodetype == XML_ENTITY_NODE) { - itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named); - } else { - notep = (xmlNotation *)xmlHashLookup(objmap->ht, named); - itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID); + if ((objmap->nodetype == XML_NOTATION_NODE) || + objmap->nodetype == XML_ENTITY_NODE) { + if (objmap->ht) { + if (objmap->nodetype == XML_ENTITY_NODE) { + itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named); + } else { + notep = (xmlNotation *)xmlHashLookup(objmap->ht, named); + if (notep) { + itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID); + } + } } } else { nodep = dom_object_get_node(objmap->baseobj); diff --git a/ext/dom/node.c b/ext/dom/node.c index 1e22aac92..0f4401e8e 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: node.c,v 1.37.2.2 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: node.c,v 1.37.2.3 2006/01/25 17:34:05 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -840,10 +840,10 @@ int dom_node_text_content_read(dom_object *obj, zval **retval TSRMLS_DC) if(str != NULL) { ZVAL_STRING(*retval, str, 1); + xmlFree(str); } else { ZVAL_EMPTY_STRING(*retval); } - xmlFree(str); return SUCCESS; } diff --git a/ext/dom/notation.c b/ext/dom/notation.c index 1bcc4387d..a546eefd3 100644 --- a/ext/dom/notation.c +++ b/ext/dom/notation.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: notation.c,v 1.9.2.1 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: notation.c,v 1.9.2.2 2006/03/03 20:15:10 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,9 +48,9 @@ Since: */ int dom_notation_public_id_read(dom_object *obj, zval **retval TSRMLS_DC) { - xmlNotationPtr nodep; + xmlEntityPtr nodep; - nodep = (xmlNotationPtr) dom_object_get_node(obj); + nodep = (xmlEntityPtr) dom_object_get_node(obj); if (nodep == NULL) { php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC); @@ -58,8 +58,8 @@ int dom_notation_public_id_read(dom_object *obj, zval **retval TSRMLS_DC) } ALLOC_ZVAL(*retval); - if (nodep->PublicID) { - ZVAL_STRING(*retval, (char *) (nodep->PublicID), 1); + if (nodep->ExternalID) { + ZVAL_STRING(*retval, (char *) (nodep->ExternalID), 1); } else { ZVAL_EMPTY_STRING(*retval); } @@ -78,9 +78,9 @@ Since: */ int dom_notation_system_id_read(dom_object *obj, zval **retval TSRMLS_DC) { - xmlNotationPtr nodep; + xmlEntityPtr nodep; - nodep = (xmlNotationPtr) dom_object_get_node(obj); + nodep = (xmlEntityPtr) dom_object_get_node(obj); if (nodep == NULL) { php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC); @@ -89,7 +89,7 @@ int dom_notation_system_id_read(dom_object *obj, zval **retval TSRMLS_DC) ALLOC_ZVAL(*retval); if (nodep->SystemID) { - ZVAL_STRING(*retval, (char *) (nodep->PublicID), 1); + ZVAL_STRING(*retval, (char *) (nodep->SystemID), 1); } else { ZVAL_EMPTY_STRING(*retval); } diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 30f693342..1060018eb 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dom.c,v 1.73.2.8 2006/01/01 12:50:06 sniper Exp $ */ +/* $Id: php_dom.c,v 1.73.2.12 2006/05/03 08:43:04 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -289,6 +289,8 @@ zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC) if (obj->prop_handler != NULL) { ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + } else if (instanceof_function(obj->std.ce, dom_node_class_entry TSRMLS_CC)) { + php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", obj->std.ce->name); } if (ret == SUCCESS) { ret = hnd->read_func(obj, &retval TSRMLS_CC); @@ -903,8 +905,7 @@ void dom_xpath_objects_free_storage(void *object TSRMLS_DC) { dom_object *intern = (dom_object *)object; - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); + zend_object_std_dtor(&intern->std TSRMLS_CC); if (intern->ptr != NULL) { xmlXPathFreeContext((xmlXPathContextPtr) intern->ptr); @@ -923,8 +924,7 @@ void dom_objects_free_storage(void *object TSRMLS_DC) dom_object *intern = (dom_object *)object; int retcount; - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); + zend_object_std_dtor(&intern->std TSRMLS_CC); if (intern->ptr != NULL && ((php_libxml_node_ptr *)intern->ptr)->node != NULL) { if (((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_DOCUMENT_NODE && ((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_HTML_DOCUMENT_NODE) { @@ -970,8 +970,6 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool dom_object *intern; intern = emalloc(sizeof(dom_object)); - intern->std.ce = class_type; - intern->std.guards = NULL; intern->ptr = NULL; intern->prop_handler = NULL; intern->document = NULL; @@ -983,8 +981,7 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler); - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); + zend_object_std_init(&intern->std, class_type TSRMLS_CC); if (hash_copy) { zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); } @@ -1089,8 +1086,7 @@ void dom_nnodemap_objects_free_storage(void *object TSRMLS_DC) php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC); - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); + zend_object_std_dtor(&intern->std TSRMLS_CC); efree(object); } diff --git a/ext/dom/tests/bug36756.phpt b/ext/dom/tests/bug36756.phpt new file mode 100644 index 000000000..e24f9f080 --- /dev/null +++ b/ext/dom/tests/bug36756.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #36756: (DOMDocument::removeChild corrupts node) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +/* Node is preserved from removeChild */ +$dom = new DOMDocument(); +$dom->loadXML('<root><child/></root>'); +$xpath = new DOMXpath($dom); +$node = $xpath->query('/root')->item(0); +echo $node->nodeName . "\n"; +$dom->removeChild($GLOBALS['dom']->firstChild); +echo "nodeType: " . $node->nodeType . "\n"; + +/* Node gets destroyed during removeChild */ +$dom->loadXML('<root><child/></root>'); +$xpath = new DOMXpath($dom); +$node = $xpath->query('//child')->item(0); +echo $node->nodeName . "\n"; +$GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild); + +echo "nodeType: " . $node->nodeType . "\n"; + +?> +--EXPECTF-- +root +nodeType: 1 +child + +Warning: Couldn't fetch DOMElement. Node no longer exists in %sbug36756.php on line %d + +Notice: Undefined property: DOMElement::$nodeType in %sbug36756.php on line %d +nodeType: diff --git a/ext/dom/tests/bug37277.phpt b/ext/dom/tests/bug37277.phpt new file mode 100644 index 000000000..4a0168417 --- /dev/null +++ b/ext/dom/tests/bug37277.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug # 37277 (cloning Dom Documents or Nodes does not work) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$dom1 = new DomDocument('1.0', 'UTF-8'); + +$xml = '<foo />'; +$dom1->loadXml($xml); + +$node = clone $dom1->documentElement; + +$dom2 = new DomDocument('1.0', 'UTF-8'); +$dom2->appendChild($dom2->importNode($node->cloneNode(true), TRUE)); + +print $dom2->saveXML(); + + +?> +--EXPECT-- + +<?xml version="1.0" encoding="UTF-8"?> +<foo/> + diff --git a/ext/dom/tests/dom007.phpt b/ext/dom/tests/dom007.phpt new file mode 100644 index 000000000..649d63033 --- /dev/null +++ b/ext/dom/tests/dom007.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test 7: DTD tests +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$xml = <<< EOXML +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE courses [ +<!ELEMENT courses (course+)> +<!ELEMENT course (title, description, temp*)> +<!ATTLIST course cid ID #REQUIRED> +<!ELEMENT title (#PCDATA)> +<!ELEMENT description (#PCDATA)> +<!ELEMENT temp (#PCDATA)> +<!ATTLIST temp vid ID #REQUIRED> +<!ENTITY test 'http://www.hpl.hp.com/semweb/2003/query_tester#'> +<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'> +<!NOTATION GIF PUBLIC "-" "image/gif"> +<!ENTITY myimage PUBLIC "-" "mypicture.gif" NDATA GIF> +]> +<courses> + <course cid="c1"> + <title>Basic Languages</title> + <description>Introduction to Languages</description> + </course> + <course cid="c6"> + <title>French I</title> + <description>Introduction to French</description> + <temp vid="c7"> + </temp> + </course> +</courses> +EOXML; + +$dom = new DOMDocument(); +$dom->loadXML($xml); + +$dtd = $dom->doctype; + +/* Notation Tests */ +$nots = $dtd->notations; + +$length = $nots->length; +echo "Length: ".$length."\n"; + +foreach ($nots AS $key=>$node) { + echo "Key $key: ".$node->nodeName." (".$node->systemId.") (".$node->publicId.")\n"; +} +print "\n"; +for($x=0; $x < $length; $x++) { + echo "Index $x: ".$nots->item($x)->nodeName." (".$nots->item($x)->systemId.") (".$nots->item($x)->publicId.")\n"; +} + +echo "\n"; +$node = $nots->getNamedItem('xxx'); +var_dump($node); + +echo "\n"; +/* Entity Decl Tests */ +$ents = $dtd->entities; +$length = $ents->length; +echo "Length: ".$length."\n"; +foreach ($ents AS $key=>$node) { + echo "Key: $key Name: ".$node->nodeName."\n"; +} +echo "\n"; +for($x=0; $x < $length; $x++) { + echo "Index $x: ".$ents->item($x)->nodeName."\n"; +} + +echo "\n"; +$node = $ents->item(3); +var_dump($node); +$node = $ents->getNamedItem('xxx'); +var_dump($node); + + +--EXPECT-- +Length: 1 +Key GIF: GIF (image/gif) (-) + +Index 0: GIF (image/gif) (-) + +NULL + +Length: 3 +Key: test Name: test +Key: rdf Name: rdf +Key: myimage Name: myimage + +Index 0: test +Index 1: rdf +Index 2: myimage + +NULL +NULL |
