jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

Escape test escaping issue #9

Closed mtdowling closed 11 years ago

mtdowling commented 11 years ago

The following test does not work correctly when run using PHP. Maybe this is something to do with how PHP handles string escaping when parsing JSON.

https://github.com/boto/jmespath/blob/develop/tests/compliance/escape.json#L37

In PHP, this creates a key containing """", which is not a valid jmespath identifier. It should be "\"\"\"".

For example (php -a):

php > var_dump(json_decode($j, true));
array(2) {
  'expression' =>
  string(5) """""""
  'result' =>
  string(11) "threequotes"
}

Does this particular test case pass in Python?

jamesls commented 11 years ago

It does pass in python, but I believe your'e correct. The inner quotes should be escaped. That would make the JSON test case:

         {
            "expression": "\"\\\"\\\"\\\"\"",
            "result": "threequotes"
         }

Interestingly enough, this tests also passes without any changes. I think the lexer in jmespath is just too lenient. Might be worth updating the compliance tests with the notion of tests that should fail to compile. In the meantime I'll at least update the tests.