diff options
Diffstat (limited to 'ext/dom')
-rw-r--r-- | ext/dom/document.c | 17 | ||||
-rw-r--r-- | ext/dom/element.c | 2 | ||||
-rw-r--r-- | ext/dom/node.c | 4 | ||||
-rw-r--r-- | ext/dom/php_dom.c | 12 | ||||
-rw-r--r-- | ext/dom/tests/bug35673.phpt | 20 | ||||
-rw-r--r-- | ext/dom/tests/bug49490.phpt | 17 | ||||
-rw-r--r-- | ext/dom/xpath.c | 31 |
7 files changed, 77 insertions, 26 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c index 4728e66b1..4ecb8fb90 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: document.c 294436 2010-02-03 18:41:27Z pajoye $ */ +/* $Id: document.c 297374 2010-04-02 20:08:15Z rrichards $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -2252,6 +2252,7 @@ PHP_FUNCTION(dom_document_save_html_file) dom_object *intern; dom_doc_propsptr doc_props; char *file; + const char *encoding; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &file, &file_len) == FAILURE) { return; @@ -2264,11 +2265,12 @@ PHP_FUNCTION(dom_document_save_html_file) DOM_GET_OBJ(docp, id, xmlDocPtr, intern); - /* encoding handled by property on doc */ + + encoding = (const char *) htmlGetMetaEncoding(docp); doc_props = dom_get_doc_props(intern->document); format = doc_props->formatoutput; - bytes = htmlSaveFileFormat(file, docp, NULL, format); + bytes = htmlSaveFileFormat(file, docp, encoding, format); if (bytes == -1) { RETURN_FALSE; @@ -2286,7 +2288,8 @@ PHP_FUNCTION(dom_document_save_html) xmlDoc *docp; dom_object *intern; xmlChar *mem; - int size; + int size, format; + dom_doc_propsptr doc_props; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) { return; @@ -2294,7 +2297,13 @@ PHP_FUNCTION(dom_document_save_html) DOM_GET_OBJ(docp, id, xmlDocPtr, intern); +#if LIBXML_VERSION >= 20623 + doc_props = dom_get_doc_props(intern->document); + format = doc_props->formatoutput; + htmlDocDumpMemoryFormat(docp, &mem, &size, format); +#else htmlDocDumpMemory(docp, &mem, &size); +#endif if (!size) { if (mem) xmlFree(mem); diff --git a/ext/dom/element.c b/ext/dom/element.c index d0b7cd488..8e457f708 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: element.c 294446 2010-02-03 20:04:38Z pajoye $ */ +/* $Id: element.c 293597 2010-01-15 21:29:56Z rrichards $ */ #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/ext/dom/node.c b/ext/dom/node.c index dc6309af0..a89026abb 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: node.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: node.c 298841 2010-05-01 18:30:38Z geissert $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -1871,7 +1871,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ inclusive_ns_prefixes[nscount] = NULL; } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, - "Inclusive namespace prefixes only allowed in exlcusive mode."); + "Inclusive namespace prefixes only allowed in exclusive mode."); } } diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 73c711046..da73a7f63 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dom.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: php_dom.c 298967 2010-05-04 12:55:26Z rrichards $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -29,6 +29,7 @@ #include "ext/standard/php_rand.h" #include "php_dom.h" #include "dom_properties.h" +#include "zend_interfaces.h" #include "ext/standard/info.h" #define PHP_XPATH 1 @@ -680,6 +681,7 @@ PHP_MINIT_FUNCTION(dom) ce.create_object = dom_nnodemap_objects_new; dom_nodelist_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); dom_nodelist_class_entry->get_iterator = php_dom_get_iterator; + zend_class_implements(dom_nodelist_class_entry TSRMLS_CC, 1, zend_ce_traversable); zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", dom_nodelist_length_read, NULL TSRMLS_CC); @@ -689,6 +691,7 @@ PHP_MINIT_FUNCTION(dom) ce.create_object = dom_nnodemap_objects_new; dom_namednodemap_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); dom_namednodemap_class_entry->get_iterator = php_dom_get_iterator; + zend_class_implements(dom_namednodemap_class_entry TSRMLS_CC, 1, zend_ce_traversable); zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", dom_namednodemap_length_read, NULL TSRMLS_CC); @@ -777,15 +780,12 @@ PHP_MINIT_FUNCTION(dom) zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL); - REGISTER_DOM_CLASS(ce, "DOMNotation", NULL, php_dom_notation_class_functions, dom_notation_class_entry); + REGISTER_DOM_CLASS(ce, "DOMNotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry); zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC); - /* Notation nodes are special */ - dom_register_prop_handler(&dom_notation_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC); - dom_register_prop_handler(&dom_notation_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC); - dom_register_prop_handler(&dom_notation_prop_handlers, "attributes", dom_node_attributes_read, NULL TSRMLS_CC); + zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry); diff --git a/ext/dom/tests/bug35673.phpt b/ext/dom/tests/bug35673.phpt new file mode 100644 index 000000000..a29ae96b6 --- /dev/null +++ b/ext/dom/tests/bug35673.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #35673 (formatOutput does not work with saveHTML). +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>This is the title</title></head></html>'; + +$htmldoc = new DOMDocument(); +$htmldoc->loadHTML($html); +$htmldoc->formatOutput = true; +echo $htmldoc->saveHTML(); +?> +--EXPECT-- +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<html><head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>This is the title</title> +</head></html> diff --git a/ext/dom/tests/bug49490.phpt b/ext/dom/tests/bug49490.phpt new file mode 100644 index 000000000..897cfee2c --- /dev/null +++ b/ext/dom/tests/bug49490.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #49490 (XPath namespace prefix conflict). +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$doc = new DOMDocument(); +$doc->loadXML('<prefix:root xmlns:prefix="urn:a" />'); + +$xp = new DOMXPath($doc); +$xp->registerNamespace('prefix', 'urn:b'); + +echo($xp->query('//prefix:root', null, false)->length . "\n"); + +?> +--EXPECT-- +0 diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index 209b213dc..d6c3487c2 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xpath.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: xpath.c 298974 2010-05-04 15:41:49Z rrichards $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,12 +48,14 @@ ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_query, 0, 0, 1) ZEND_ARG_INFO(0, expr) - ZEND_ARG_OBJ_INFO(0, context, DOMNode, 0) + ZEND_ARG_OBJ_INFO(0, context, DOMNode, 1) + ZEND_ARG_INFO(0, registerNodeNS) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_evaluate, 0, 0, 1) ZEND_ARG_INFO(0, expr) - ZEND_ARG_OBJ_INFO(0, context, DOMNode, 0) + ZEND_ARG_OBJ_INFO(0, context, DOMNode, 1) + ZEND_ARG_INFO(0, registerNodeNS) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_register_php_functions, 0, 0, 0) @@ -385,9 +387,10 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ dom_object *nodeobj; char *expr; xmlDoc *docp = NULL; - xmlNsPtr *ns; + xmlNsPtr *ns = NULL; + zend_bool register_node_ns = 1; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|O", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|O!b", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry, ®ister_node_ns) == FAILURE) { return; } @@ -420,13 +423,15 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ ctxp->node = nodep; - /* Register namespaces in the node */ - ns = xmlGetNsList(docp, nodep); + if (register_node_ns) { + /* Register namespaces in the node */ + ns = xmlGetNsList(docp, nodep); - if (ns != NULL) { - while (ns[nsnbr] != NULL) - nsnbr++; - } + if (ns != NULL) { + while (ns[nsnbr] != NULL) + nsnbr++; + } + } ctxp->namespaces = ns; @@ -518,14 +523,14 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ } /* }}} */ -/* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context]); */ +/* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context [, boolean registerNodeNS]]); */ PHP_FUNCTION(dom_xpath_query) { php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_QUERY); } /* }}} end dom_xpath_query */ -/* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context]); */ +/* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context [, boolean registerNodeNS]]); */ PHP_FUNCTION(dom_xpath_evaluate) { php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_EVALUATE); |