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

Fix #2709 (make OR operator work in multitool queries) #2710

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Sarif/Query/Evaluators/ExpressionEvaluators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ public OrEvaluator(IEnumerable<IExpressionEvaluator<T>> terms)

public void Evaluate(ICollection<T> list, BitArray matches)
{
BitArray termMatches = new BitArray(list.Count);

foreach (IExpressionEvaluator<T> term in _terms)
{
// Add each term's matches to the same set
term.Evaluate(list, matches);
// Get matches for the term
termMatches.SetAll(false);
term.Evaluate(list, termMatches);

// Union with matches so far
matches.Or(termMatches);

// Stop if everything has already matched
if (matches.TrueCount() == list.Count) { break; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public void QueryCommand_Basics()
// All Results: No filter
RunAndVerifyCount(5, new QueryOptions() { Expression = "", InputFilePath = filePath });

// Or operator
RunAndVerifyCount(2, new QueryOptions() { Expression = "Uri >| test_key.pem || Uri >| test_rsa_privkey.pem", InputFilePath = filePath });

// Rule filtering
RunAndVerifyCount(1, new QueryOptions() { Expression = "RuleId = 'CSCAN0020/0'", InputFilePath = filePath });
RunAndVerifyCount(4, new QueryOptions() { Expression = "RuleId = 'CSCAN0060/0'", InputFilePath = filePath });
Expand Down Expand Up @@ -82,7 +85,6 @@ public void QueryCommand_Properties()
RunAndVerifyCount(0, new QueryOptions() { Expression = "properties.patchPublicationDate < '2022-04-25T00:00:00'", InputFilePath = filePath });
}


private void RunAndVerifyCount(int expectedCount, QueryOptions options)
{
options.ReturnCount = true;
Expand Down
Loading