php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70523 check xpath expression
Submitted: 2015-09-17 21:02 UTC Modified: 2015-09-17 21:24 UTC
From: kakkau at grr dot la Assigned:
Status: Open Package: DOM XML related
PHP Version: irrelevant OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-09-17 21:02 UTC] 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"; }

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-17 21:24 UTC] kakkau at grr dot la
-PHP Version: 5.6.13 +PHP Version: irrelevant
 [2015-09-17 21:24 UTC] kakkau at grr dot la
php version irrelevant as the return value on failures is false. should be a unique one or provide a function to compensate this behaviour.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 20 14:01:23 2020 UTC