Podger2016 / jsonpath

Automatically exported from code.google.com/p/jsonpath
0 stars 0 forks source link

filter expression doesn't work properly #11

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
==call==
jsonPath(arr, '$..book[?(@.isbn)]').length
==input==
var arr={ "store": {
    "book": { "isbn": "0-553-21311-3"} 
};

What is the expected output? What do you see instead?
Expected 1, returned 0

What version of the product are you using? On what operating system?
jsonpath-0.8.0.js
¡Javascript!

Please provide any additional information below.
The problem is that in the "trace" function, in the case of "[?(expr)]" the
function P.walk is applied for arrays but the simple case is not handled.
A temporal solution, that works is add a line of code to the "[?(expr)]" case:
----------Old code------------:
else if (/^\?\(.*?\)$/.test(loc)) // [?(expr)]
  P.walk(loc, x, val, path, function(m,l,x,v,p) { if
(P.eval(l.replace(/^\?\((.*?)\)$/,"$1"),v[m],m)) P.trace(m+";"+x,v,p); });
----------New code------------:
else if (/^\?\(.*?\)$/.test(loc)){ // [?(expr)]  Added curly brace, 2 lines
 if (P.eval(loc.replace(/^\?\((.*?)\)$/,"$1"),val,null))
P.trace(x,val,path);  //Added, to handle just this node
 P.walk(loc, x, val, path, function(m,l,x,v,p) { if
(P.eval(l.replace(/^\?\((.*?)\)$/,"$1"),v[m],m)) P.trace(m+";"+x,v,p); });
            }

Original issue reported on code.google.com by carellan...@gmail.com on 13 Aug 2009 at 10:40