h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
564 stars 85 forks source link

Fix exception type on certain syntax errors #130

Closed oskarrrrrrr closed 10 months ago

oskarrrrrrr commented 11 months ago

Raise JsonPathParserError when there is a syntax error at the end of path string. Before, for example, 'foo[*' would raise an AttributeError instead.

The bug was in p_error method, it was assumed that it always got a token but it gets a None whenever the error is at the end of path.

See: https://ply.readthedocs.io/en/latest/ply.html?highlight=p_error#syntax-error-handling ("if the syntax error is due to reaching the end-of-file, p_error() is called with an argument of None")

michaelmior commented 10 months ago

@oskarrrrrrr Thanks! Looks great :)