julesfern / spahql

A query language for Javascript data. Extracted from Spah.
MIT License
325 stars 20 forks source link

Select query fails for key with special characters #29

Open sajus opened 9 years ago

sajus commented 9 years ago

Select query returns the entire JSON object, if there is any special character in the JSON key.

Consider for e.g [BadgerFish Convention] https://developer.mozilla.org/en-US/docs/JXON#Algorithm_.232.3A_a_less_verbose_way

Here the keys will have special character appended and select query fails. Rather it returns the entire JSON as response.

You can reproduce this issue by visiting the below URL. http://danski.github.io/spahql/repl.html

Update the JSON 'arr1' with '#arr1' and run '/#arr1/0' query.

Thanks Saju

julesfern commented 9 years ago

Interesting - the syntax was never authored with newer JSON patterns like JSON-LD in mind, but we should be able to increase the range of allowed key characters such that it includes everything minus SpahQL's filter tokens ([ and ]) and comparator tokens.

The only difficulty will be in assertion/comparison queries where a query such as /one key with spaces//other key with spaces == /some other key will be ambiguous in that the space before the equality operator could be either syntactic or semantic.

Do you think there's a better way to wrap assertion queries or to identify spaces in keys? We could support a key literal like /foo/"something with keys" for instance.