Req #70523 [Opn]: check xpath expression
| From: | kakkau at grr dot la | Date: | Thu, 17 Sep 2015 21:24:51 +0000 |
| Subject: | Req #70523 [Opn]: check xpath expression | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196062@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70523&edit=1
ID: 70523
User updated by: kakkau at grr dot la
Reported by: kakkau at grr dot la
Summary: check xpath expression
Status: Open
Type: Feature/Change Request
Package: DOM XML related
Operating System: any
-PHP Version: 5.6.13
+PHP Version: irrelevant
Block user comment: N
Private report: N
New Comment:
php version irrelevant as the return value on failures is false. should be a unique one or provide a
function to compensate this behaviour.
Previous Comments:
------------------------------------------------------------------------
[2015-09-17 21:02:29] kakkau at grr dot la
Description:
------------
---
From manual page: http://www.php.net/class.domxpath
---
in some cases the return value of DOMXPath::evaluate could be unfavorable.
For example what if a valid xpath expression like
'false()' or 'count(...)=0' evaluates to false and you want to catch
e.g. malformed xpath expressions which return false as well?
how to distinguish those scenarios?
therefor it would be useful to have a function to
- check the xpath expression first or
- having some kind of unique value returned
in case the evaluation failed
Test script:
---------------
<?php
$d = new DOMDocument();
$xs = '<?xml version="1.0" ?><root><foo /></root>';
$d->loadXML($xs);
$x = new DOMXPath($d);
// simple eval
$eval = $x->evaluate('false()');
if(!$eval) { echo "BOOBOO"; }
// complex but valid eval
$eval = $x->evaluate('count(//foo)=0');
if(!$eval) { echo "BOOBOO"; }
// bad eval
$eval = $x->evaluate(')');
if(!$eval) { echo "BOOBOO"; }
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70523&edit=1