Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid cql-json and expression is parsed into "wrong" ast #47

Open
AsgerPetersen opened this issue Jun 8, 2022 · 5 comments
Open

Invalid cql-json and expression is parsed into "wrong" ast #47

AsgerPetersen opened this issue Jun 8, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@AsgerPetersen
Copy link

I cannot find any description of how pygeofilter is supposed to behave when it meets invalid filters. The issue is written assuming that pygeofilter should fail when parsing invalid filters.

Example 1 where pygeofilter silently ignores invalid and expression:

>>> import pygeofilter.ast
>>> from pygeofilter.parsers.cql_json import parse as parse_json
>>> 
>>> cql_json = { "intersects": [ { "property": "geometry" }, { "type": "Point", "coordinates": [ 10.4064, 55.3951 ] } ], "and": [ {"eq": [ { "property": "direction" }, "east" ] } ] }
>>> print(pygeofilter.ast.get_repr(parse_json(cql_json)))
INTERSECTS(ATTRIBUTE geometry, Geometry(geometry={'type': 'Point', 'coordinates': [10.4064, 55.3951]}))

Example 2 where pygeofilter parses invalid and into a simple comparison:

>>> import pygeofilter.ast
>>> from pygeofilter.parsers.cql_json import parse as parse_json
>>> 
>>> cql_json = { "and": [ {"eq": [ { "property": "direction" }, "east" ] } ] }
>>> print(pygeofilter.ast.get_repr(parse_json(cql_json)))
ATTRIBUTE direction = 'east'

Needless to say it would be a better user experience if both these examples would fail with some meaningful message.

@constantinius
Copy link
Contributor

@AsgerPetersen

Thanks for reporting this issue. The JSON based parsers are indeed rather simple and will ignore extra attributes of the identified node. But I agree, extra arguments should not be silently ignored but reported as errors. Contributions are welcome.

Regarding the and with only a single item: I concur, we should add a check to mark these cases as errors!

@bitner
Copy link
Contributor

bitner commented Jun 8, 2022 via email

@AsgerPetersen
Copy link
Author

Thank you both. Unfortunately I there isn´t enough time for me to participate actively in all the great projects I use. I try to my best to take the time to at least write decent bug reports.

@bitner that makes sense, but doesn´t the spec require at least 2 items? So other parsers would probably behave differently.

@constantinius
Copy link
Contributor

Unfortunately I there isn´t enough time for me to participate actively in all the great projects I use. I try to my best to take the time to at least write decent bug reports.

Your contribution in the form of bug reports is very much appreciated! I did not mean to impose further work on you, but rather something I don't have the resources to fix right now. So if anyone wants to step up and take this over, I'd be very grateful!

@bitner that makes sense, but doesn´t the spec require at least 2 items? So other parsers would probably behave differently.

That is indeed true, the spec mandates at least 2 items

@constantinius constantinius added bug Something isn't working good first issue Good for newcomers labels Jun 9, 2022
@bitner
Copy link
Contributor

bitner commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants