Fix edge case in OverpassQL query rewriting #1144
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes maproulette/maproulette3#2414
My recent changes to the query rewriting logic had broken the (perfectly valid) query in the linked issue. The problem is that query has settings formatted over multiple lines. I noted in a comment that
rewriteQuery
wouldn't understand these settings, but what I didn't think about was that this would mean it would prepend a second set of settings, and having more than one settings statement is a syntax error in OverpassQL.The fix I'm proposing here is to check if there appear to be any settings given anywhere in the query, using a crude
String.contains
check that should have no false negatives. If there are,rewriteQuery
will return the query unmodified, and only if there aren't will it prepend the default[out:json]
andtimeout
settings.I'd appreciate a careful review of this. The list of OverpassQL settings is here and is what I based the
settings
array in the PR on.An assumption I'm making with this code that should be reviewed is that an OverpassQL setting starts with
[
+ a setting name +:
, e.g.[out:json]
. OverpassQL query expressions often also contain[
, e.g.way[highway = motorway];
, and they may also contain:
, e.g.way["piste:type" = "advanced"];
ornode[amenity = parking](around:100);
. However, I believe they never contain[
+ a bare string +:
, unless that entire sequence appeared inside a quoted string. I'm only searching for a list of known settings names, not\[.*:
, so the odds of this triggering a false positive seem very low. Therefore, I believe that the check on line 801 should always be true if the query contains any settings, and additionally should almost never be true if the query does not contain any settings (something likenode[name ~ "[out:xml]"]
would trigger a false positive but that's a pretty contrived edge case IMO).Feedback or suggested testcases are welcome.