Patch bug49490 for Documentation problem Bug #49490
Patch version 2010-05-02 16:00 UTC
Return to Bug #49490 |
Download this patch
Patch Revisions:
Developer: david.zuelke@bitextender.com
Index: ext/dom/tests/bug49490.phpt
===================================================================
--- ext/dom/tests/bug49490.phpt (Revision 0)
+++ ext/dom/tests/bug49490.phpt (Revision 0)
@@ -0,0 +1,17 @@
+--TEST--
+Bug #49490 (XPath namespace prefix conflict)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$doc = new DOMDocument('1.0', 'utf-8');
+$doc->loadXML('<foo:foo xmlns:foo="urn:foo" id="zomg"><bar:foo xmlns:bar="urn:bar" id="lol" /></foo:foo>');
+$xpath = new DOMXPath($doc);
+var_dump($xpath->evaluate('string(//foo:foo/@id)'));
+$xpath->registerNamespace('foo', 'urn:bar');
+var_dump($xpath->evaluate('string(//foo:foo/@id)'));
+?>
+--EXPECT--
+string(4) "zomg"
+string(3) "lol"
Index: ext/dom/xpath.c
===================================================================
--- ext/dom/xpath.c (Revision 298873)
+++ ext/dom/xpath.c (Arbeitskopie)
@@ -380,12 +380,12 @@
xmlXPathContextPtr ctxp;
xmlNodePtr nodep = NULL;
xmlXPathObjectPtr xpathobjp;
- int expr_len, ret, nsnbr = 0, xpath_type;
+ int expr_len, ret, nsnbr, fnsnbr = 0, xpath_type;
dom_xpath_object *intern;
dom_object *nodeobj;
char *expr;
xmlDoc *docp = NULL;
- xmlNsPtr *ns;
+ xmlNsPtr *ns, *fns;
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) {
return;
@@ -420,23 +420,37 @@
ctxp->node = nodep;
- /* Register namespaces in the node */
+ /* fetch all namespaces in the node */
ns = xmlGetNsList(docp, nodep);
- if (ns != NULL) {
- while (ns[nsnbr] != NULL)
- nsnbr++;
- }
+ if (ns != NULL) {
+ while (ns[nsnbr] != NULL)
+ nsnbr++;
+
+ fns = (xmlNsPtr *) xmlMalloc((nsnbr + 1) * sizeof(xmlNsPtr));
+
+ nsnbr = 0;
+ /* register all the namespaces... */
+ while (ns[nsnbr] != NULL) {
+ /* ... whose prefixes have not previously been registered using DOMXPath::registerNamespace() (see bug #49490) */
+ if(xmlXPathNsLookup(ctxp, ns[nsnbr]->prefix) == NULL) {
+ fns[fnsnbr++] = ns[nsnbr];
+ }
+ nsnbr++;
+ }
+ fns[fnsnbr] = NULL;
+ } else {
+ fns = NULL;
+ }
+ ctxp->namespaces = fns;
+ ctxp->nsNr = fnsnbr;
-
- ctxp->namespaces = ns;
- ctxp->nsNr = nsnbr;
-
xpathobjp = xmlXPathEvalExpression(expr, ctxp);
ctxp->node = NULL;
if (ns != NULL) {
xmlFree(ns);
+ xmlFree(fns);
ctxp->namespaces = NULL;
ctxp->nsNr = 0;
}
|