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

SLD Filters missing due to logicial keywords in expressions #7178

Merged
merged 8 commits into from
Oct 29, 2024

Conversation

geographika
Copy link
Member

When using WMS GetStyles requests to generate SLD I noticed some filters were missing. On debugging it became apparent that any string containing a logical operator was failing to generate a filter:

EXPRESSION ("[Property1]" = "Not Applicable")

Was missing the expected filter:

<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>Property1</ogc:PropertyName><ogc:Literal>Not Applicable</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>

msSLDNumberOfLogicalOperators had a simple search for AND, NOT, and OR that was finding these words in strings causing errors. This fix attempts to tokenize the string, leaving quoted strings intact to avoid this. It is by no means perfect, and I also had to change previous test cases to have spaces around keywords e.g. (([FID] > 1)And([FID] <= 10)) so that they pass.

MapServer seems to be missing a parsing engine for expressions (or at least I can't find anything in the codebase). Without this any SLD expression building is going to be flaky. See also #5894.

@geographika
Copy link
Member Author

CI currently failing due to #7179

@rouault
Copy link
Contributor

rouault commented Oct 22, 2024

This indeed feels like band-aid fixing, but better than what we have, so why not. Perhaps a TODO/FIXME comment in the code itself would be welcome. msSLDGetLogicalOperator() would also benefit from a similar logic.
Ideally we'd perhaps need to use yylex() and a new SLD parsing mode in mapparser.y

@geographika
Copy link
Member Author

This indeed feels like band-aid fixing, but better than what we have, so why not. Perhaps a TODO/FIXME comment in the code itself would be welcome. msSLDGetLogicalOperator() would also benefit from a similar logic. Ideally we'd perhaps need to use yylex() and a new SLD parsing mode in mapparser.y

Yes, these changes are very much trying to make an error-prone approach slightly less buggy. With further tests it appears both msSLDGetLogicalOperator, msSLDGetRightExpressionOfOperator, and msSLDGetLeftExpressionOfOperator have the same issues - see the test where "An And value" is converted to "An".

@sdlime - could any of the changes in https://mapserver.org/development/rfc/ms-rfc-64.html be used here instead of the current string searching approach?

I've a copy of the Lex Yacc book but never got much past the first chapter..

@geographika
Copy link
Member Author

I've updated the function so the previous cases such as AND( and OR( still pass, so anything that previously worked should continue to do so. I keep thinking that expression parsing is implemented somewhere - msEvalTextExpressionInternal seems close but returns a true/false rather than a parse tree that could be used for converting expressions from Mapfile to SLD.

@rouault rouault added this to the 8.4.0 Release milestone Oct 29, 2024
@rouault rouault merged commit 4726b9c into MapServer:main Oct 29, 2024
17 checks passed
rouault pushed a commit that referenced this pull request Nov 28, 2024
This pull request allows <> to be used for "not equal to" logical expressions, along with the already supported ne and !=. Fixes #6950.

When creating SLD filters expressions are created by checking values in strings, so modifications have been added to mapogcsld.cpp have been made to support these. There are still issues around this approach for creating SLD filters as noted in #7178.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants