svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/dom/tests/bug49490.phpt branches/PHP_5_3/ext/dom/xpath.c
trunk/ext/dom/tests/bug49490.phpt trunk/ext/dom/xpath.c
| From: | Rob Richards | Date: | Tue, 04 May 2010 15:41:49 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/dom/tests/bug49490.phpt branches/PHP_5_3/ext/dom/xpath.c trunk/ext/dom/tests/bug49490.phpt trunk/ext/dom/xpath.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-62547@lists.php.net to get a copy of this message | ||
rrichards Tue, 04 May 2010 15:41:49 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=298974
Log:
fix bug #49490 (XPath namespace prefix conflict)
add test
Bug: http://bugs.php.net/49490 (Assigned) XPath namespace
prefix conflict
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
A php/php-src/branches/PHP_5_3/ext/dom/tests/bug49490.phpt
U php/php-src/branches/PHP_5_3/ext/dom/xpath.c
A php/php-src/trunk/ext/dom/tests/bug49490.phpt
U php/php-src/trunk/ext/dom/xpath.c
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2010-05-04 15:11:41 UTC (rev 298973)
+++ php/php-src/branches/PHP_5_3/NEWS 2010-05-04 15:41:49 UTC (rev 298974)
@@ -126,6 +126,7 @@
- Fixed bug #49700 (memory leaks in php_date.c if garbage collector is
enabled). (Dmitry)
- Fixed bug #49576 (FILTER_VALIDATE_EMAIL filter needs updating) (Rasmus)
+- Fixed bug #49490 (XPath namespace prefix conflict). (Rob)
- Fixed bug #49429 (odbc_autocommit doesn't work). (Felipe)
- Fixed bug #49234 (mysqli_ssl_set not found). (Andrey)
- Fixed bug #49192 (PHP crashes when GC invoked on COM object). (Stas)
Added: php/php-src/branches/PHP_5_3/ext/dom/tests/bug49490.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/dom/tests/bug49490.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/dom/tests/bug49490.phpt 2010-05-04 15:41:49 UTC (rev 298974)
@@ -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
Modified: php/php-src/branches/PHP_5_3/ext/dom/xpath.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/dom/xpath.c 2010-05-04 15:11:41 UTC (rev 298973)
+++ php/php-src/branches/PHP_5_3/ext/dom/xpath.c 2010-05-04 15:41:49 UTC (rev 298974)
@@ -48,12 +48,14 @@
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 @@
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 @@
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 @@
}
/* }}} */
-/* {{{ 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);
Added: php/php-src/trunk/ext/dom/tests/bug49490.phpt
===================================================================
--- php/php-src/trunk/ext/dom/tests/bug49490.phpt (rev 0)
+++ php/php-src/trunk/ext/dom/tests/bug49490.phpt 2010-05-04 15:41:49 UTC (rev 298974)
@@ -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
Modified: php/php-src/trunk/ext/dom/xpath.c
===================================================================
--- php/php-src/trunk/ext/dom/xpath.c 2010-05-04 15:11:41 UTC (rev 298973)
+++ php/php-src/trunk/ext/dom/xpath.c 2010-05-04 15:41:49 UTC (rev 298974)
@@ -48,12 +48,14 @@
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 @@
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 @@
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 @@
}
/* }}} */
-/* {{{ 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);