Req #70523 [NEW]: check xpath expression
| From: | kakkau at grr dot la | Date: | Thu, 17 Sep 2015 21:02:32 +0000 |
| Subject: | Req #70523 [NEW]: check xpath expression | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196061@lists.php.net to get a copy of this message | ||
From: kakkau at grr dot la
Operating system: any
PHP version: 5.6.13
Package: DOM XML related
Bug Type: Feature/Change Request
Bug description:check xpath expression
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 bug report at https://bugs.php.net/bug.php?id=70523&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70523&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70523&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70523&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70523&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70523&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70523&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70523&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70523&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70523&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70523&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70523&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70523&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70523&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70523&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70523&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70523&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70523&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70523&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70523&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70523&r=mysqlcfg