rrichards               Tue Dec 16 12:53:29 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/dom/tests      bug46849.phpt 

  Modified files:              
    /php-src/ext/dom    php_dom.c 
  Log:
  MFH: fix bug #46849 (Cloning DOMDocument doesn't clone the properties)
  fix some warnings
  add test
  
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/php_dom.c?r1=1.73.2.12.2.12.2.12&r2=1.73.2.12.2.12.2.13&diff_format=u
Index: php-src/ext/dom/php_dom.c
diff -u php-src/ext/dom/php_dom.c:1.73.2.12.2.12.2.12 
php-src/ext/dom/php_dom.c:1.73.2.12.2.12.2.13
--- php-src/ext/dom/php_dom.c:1.73.2.12.2.12.2.12       Mon Nov 17 11:27:54 2008
+++ php-src/ext/dom/php_dom.c   Tue Dec 16 12:53:29 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.c,v 1.73.2.12.2.12.2.12 2008/11/17 11:27:54 felipe Exp $ */
+/* $Id: php_dom.c,v 1.73.2.12.2.12.2.13 2008/12/16 12:53:29 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -172,6 +172,31 @@
        }
 }
 
+static void dom_copy_doc_props(php_libxml_ref_obj *source_doc, 
php_libxml_ref_obj *dest_doc)
+{
+       dom_doc_propsptr source, dest;
+       
+       if (source_doc && dest_doc) {
+               
+               source = dom_get_doc_props(source_doc);
+               dest = dom_get_doc_props(dest_doc);
+
+               dest->formatoutput = source->formatoutput;
+               dest->validateonparse = source->validateonparse;
+               dest->resolveexternals = source->resolveexternals;
+               dest->preservewhitespace = source->preservewhitespace;
+               dest->substituteentities = source->substituteentities;
+               dest->stricterror = source->stricterror;
+               dest->recover = source->recover;
+               if (source->classmap) {
+                       ALLOC_HASHTABLE(dest->classmap);
+                       zend_hash_init(dest->classmap, 0, NULL, NULL, 0);
+                       zend_hash_copy(dest->classmap, source->classmap, NULL, 
NULL, sizeof(zend_class_entry *));
+               }
+
+       }
+}
+
 int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry 
*basece, zend_class_entry *ce TSRMLS_DC)
 {
        dom_doc_propsptr doc_props;
@@ -1078,6 +1103,9 @@
                                }
                                
php_libxml_increment_doc_ref((php_libxml_node_object *)clone, cloned_node->doc 
TSRMLS_CC);
                                
php_libxml_increment_node_ptr((php_libxml_node_object *)clone, cloned_node, 
(void *)clone TSRMLS_CC);
+                               if (intern->document != clone->document) {
+                                       dom_copy_doc_props(intern->document, 
clone->document);
+                               }
                        }
 
                }
@@ -1371,8 +1399,8 @@
 
        while (nodep != NULL && (*cur <= index || index == -1)) {
                if (nodep->type == XML_ELEMENT_NODE) {
-                       if (xmlStrEqual(nodep->name, local) || xmlStrEqual("*", 
local)) {
-                               if (ns == NULL || (nodep->ns != NULL && 
(xmlStrEqual(nodep->ns->href, ns) || xmlStrEqual("*", ns)))) {
+                       if (xmlStrEqual(nodep->name, (xmlChar *)local) || 
xmlStrEqual((xmlChar *)"*", (xmlChar *)local)) {
+                               if (ns == NULL || (nodep->ns != NULL && 
(xmlStrEqual(nodep->ns->href, (xmlChar *)ns) || xmlStrEqual((xmlChar *)"*", 
(xmlChar *)ns)))) {
                                        if (*cur == index) {
                                                ret = nodep;
                                                break;
@@ -1479,9 +1507,9 @@
                return NAMESPACE_ERR;
        }
        
-       *localname = xmlSplitQName2(qname, (xmlChar **) prefix);
+       *localname = (char *)xmlSplitQName2((xmlChar *)qname, (xmlChar **) 
prefix);
        if (*localname == NULL) {
-               *localname = xmlStrdup(qname);
+               *localname = (char *)xmlStrdup((xmlChar *)qname);
                if (*prefix == NULL && uri_len == 0) {
                        return 0;
                }
@@ -1517,10 +1545,10 @@
 
        *errorcode = 0;
 
-       if (! ((prefix && !strcmp (prefix, "xml"  ) && strcmp(uri, 
XML_XML_NAMESPACE)) ||
-                  (prefix && !strcmp (prefix, "xmlns") && strcmp(uri, 
DOM_XMLNS_NAMESPACE)) ||
-                  (prefix && !strcmp(uri, DOM_XMLNS_NAMESPACE) && strcmp 
(prefix, "xmlns")))) {
-               nsptr = xmlNewNs(nodep, uri, prefix);
+       if (! ((prefix && !strcmp (prefix, "xml") && strcmp(uri, (char 
*)XML_XML_NAMESPACE)) ||
+                  (prefix && !strcmp (prefix, "xmlns") && strcmp(uri, (char 
*)DOM_XMLNS_NAMESPACE)) ||
+                  (prefix && !strcmp(uri, (char *)DOM_XMLNS_NAMESPACE) && 
strcmp (prefix, "xmlns")))) {
+               nsptr = xmlNewNs(nodep, (xmlChar *)uri, (xmlChar *)prefix);
        }
 
        if (nsptr == NULL) {
@@ -1539,7 +1567,7 @@
        if (node == NULL)
                return NULL;
 
-       if (localName == NULL || xmlStrEqual(localName, "")) {
+       if (localName == NULL || xmlStrEqual(localName, (xmlChar *)"")) {
                cur = node->nsDef;
                while (cur != NULL) {
                        if (cur->prefix == NULL  && cur->href != NULL) {

http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/bug46849.phpt?view=markup&rev=1.1
Index: php-src/ext/dom/tests/bug46849.phpt
+++ php-src/ext/dom/tests/bug46849.phpt
--TEST--
Bug #46849 (Cloning DOMDocument doesn't clone the properties).
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
$dom = new DOMDocument;
$dom->formatOutput = 1;
var_dump($dom->formatOutput);

$dom2 = clone $dom;
var_dump($dom2->formatOutput);
?>
--EXPECT--
bool(true)
bool(true)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to