-
Notifications
You must be signed in to change notification settings - Fork 8k
Add DOMXPath::$enableRegisterNodeNS property #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--TEST-- | ||
Bug #55700 (Disable automatic registration on a DOMXpath object) | ||
--SKIPIF-- | ||
<?php require_once('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$dom = new DOMDocument(); | ||
$dom->loadXML( | ||
'<foobar><a:foo xmlns:a="urn:a">'. | ||
'<b:bar xmlns:b="urn:b"/></a:foo>'. | ||
'</foobar>' | ||
); | ||
$xpath = new DOMXPath($dom); | ||
|
||
// disable automatic namespace registration | ||
var_dump($xpath->enableRegisterNodeNS); | ||
$xpath->enableRegisterNodeNS = FALSE; | ||
var_dump($xpath->enableRegisterNodeNS); | ||
|
||
$context = $dom->documentElement->firstChild; | ||
$xpath->registerNamespace('a', 'urn:b'); | ||
var_dump( | ||
$xpath->evaluate( | ||
'descendant-or-self::a:*', | ||
$context | ||
)->item(0)->tagName | ||
); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(false) | ||
string(5) "b:bar" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,25 @@ int dom_xpath_document_read(dom_object *obj, zval **retval TSRMLS_DC) | |
} | ||
/* }}} */ | ||
|
||
/* {{{ enableRegisterNodeNS boolean | ||
readonly=no | ||
*/ | ||
int dom_xpath_enable_register_node_ns_read(dom_object *obj, zval **retval TSRMLS_DC) | ||
{ | ||
MAKE_STD_ZVAL(*retval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should show a leak in a debug build, but your test never reads the property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no leak here (that I can see, checked with a debug build) - note that this is a property accessor and not a method, as such I've added two reads to the test to cover the code path it previously did not hit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, sorry for picking around, I did not see that dom_read_property() already takes care of that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this also is handled by the caller at https://github.com/php/php-src/blob/PHP-5.6/ext/dom/php_dom.c#L367-369 Unless I'm misreading? |
||
ZVAL_BOOL(*retval, ((dom_xpath_object *)obj)->enable_register_node_ns); | ||
|
||
return SUCCESS; | ||
} | ||
|
||
int dom_xpath_enable_register_node_ns_write(dom_object *obj, zval *newval TSRMLS_DC) | ||
{ | ||
((dom_xpath_object *)obj)->enable_register_node_ns = zend_is_true(newval); | ||
|
||
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
/* {{{ proto boolean dom_xpath_register_ns(string prefix, string uri); */ | ||
PHP_FUNCTION(dom_xpath_register_ns) | ||
{ | ||
|
@@ -430,6 +449,11 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ | |
|
||
ctxp->node = nodep; | ||
|
||
if (ZEND_NUM_ARGS() < 3) { | ||
/* register_node_ns was not passed, fetch default value from the property */ | ||
register_node_ns = intern->enable_register_node_ns; | ||
} | ||
|
||
if (register_node_ns) { | ||
/* Register namespaces in the node */ | ||
ns = xmlGetNsList(docp, nodep); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property handlers need to be exported. The build fails because of undefined identifiers.