RuddenberryL / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

property names with dashes in them are not evaluated in filters #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version 0.5.5

The PATTERN for ListEvalFilter incorrectly tests for property names that just 
contain \\w chars, which is a class that does not include dashes ('-')

Here is a test case. Given this object:

{
 "store":{
  "book":[
   {
    "category":"reference",
    "author":"Nigel Rees",
    "title":"Sayings of the Century",
    "display-price":8.95
   },
   {
    "category":"fiction",
    "author":"Evelyn Waugh",
    "title":"Sword of Honour",
    "display-price":12.99
   },
   {
    "category":"fiction",
    "author":"J. R. R. Tolkien",
    "title":"The Lord of the Rings",
    "isbn":"0-395-19395-8",
    "display-price":22.99
   },
  ],
  "bicycle":{
   "color":"red",
   "display-price":19.95
  }
 }
}

This pattern does not return any results:

$.store.book[?(@['display-price'] < 10)].title

However, it does return one result when tested against the PHP version found 
here:

http://jsonpath.curiousconcept.com/

Original issue reported on code.google.com by m...@thebishops.org on 13 Dec 2011 at 11:59

GoogleCodeExporter commented 9 years ago
Thank you Matt Bishop for the contribution of tests.

Original comment by kalle.st...@gmail.com on 28 Feb 2012 at 1:06

GoogleCodeExporter commented 9 years ago

Original comment by kalle.st...@gmail.com on 28 Feb 2012 at 1:09

GoogleCodeExporter commented 9 years ago
Sorry Kalle, this is not fixed. I got confused in writing the test. The code I 
pushed adds a test for directly finding an attribute with a dash in the 
property name. This bug report addresses using a filter "@" to find a property 
with a dash in it. This still does not work in v56.

I am going to spend a bit of time looking at this specific issue on your new 
codebase to see if I can find and fix it as it is critical in our use of 
json-path.

Congratulations on your redesign! I like the SPI approach.

Original comment by m...@thebishops.org on 28 Feb 2012 at 3:02

GoogleCodeExporter commented 9 years ago
I tracked down the bug, it's in PathTokenizer.splitPath().  When you have an 
expression like:

    [?(@['display-price'] < 10)]

The splitPath method identifies the first '[' and then calls extract(']') to 
find the whole expression. The problem is, the whole expression includes a 
second, array reference, so the Tokenizer breaks it into two fragments:

    [?(@['display-price']

and

     < 10)]

The solution is to not split on the first ']' but on the second one. This means 
extract has to be smarter and count '[' chars along the way to find the final 
']'.

Interestingly this breaks for other filters with arrays like 
$.store.book[?(@['isbn'])].isbn but the Filters clean this up with their call 
to trim(5, 2).

Original comment by m...@thebishops.org on 28 Feb 2012 at 9:13