Fix negated filters logic: non-boolean AND/OR #247
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.
Long story short
Original filter logic was simple:
But then we started supporting negated filters (#179) and simply defined
negative match
asno match
. It doesn't work because (as @Antelox found)!linux OR !windows
matcheswindows
making that filter a no-op.Negated filters logic was then fixed by #223, but @ups1decyber found corner cases where proposed algorithm doesn't work as expected (#246)
What was changed?
After analyzing the case, I found that we still want to follow AND/OR logic but we need special value for
negative match
.[{"type": "sample", "platform": "win32"}, {"type": "different", "platform": "!win32"}
means: "type MUST BE sample AND platform MUST BE win32" OR "type MUST BE different AND platform CAN'T BE win32"
so
!linux OR !windows
indeed matcheswindows
but it's special case of match: negative match. Mismatched values (0) should still follow AND/OR logic, but matches should have sign that determines if it's positive match or negative match (1 or -1). Negative match overrides the positive one, because positive match is also lack of filter for specific header value.Finally non-boolean logic is converted to the boolean value: False for mismatch (0) and negative match (-1), True for positive match (1).
In addition, I added test cases that should cover specific corner cases including these found by @ups1decyber