-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Test: Add support for RelatedLocation tag and use in a JS query #18810
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
Changes from 1 commit
e2fe74c
cd2c4d5
cd0fd02
694f01a
ae161f1
92e1023
5f2e5ab
bb8f452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -779,22 +779,33 @@ module TestPostProcessing { | |
) | ||
} | ||
|
||
private string getTagRegex() { | ||
exists(string sourceSinkTags | | ||
( | ||
getQueryKind() = "problem" | ||
or | ||
not exists(getSourceTag(_)) and | ||
not exists(getSinkTag(_)) | ||
) and | ||
sourceSinkTags = "" | ||
or | ||
sourceSinkTags = "|" + getSourceTag(_) + "|" + getSinkTag(_) | ||
bindingset[x, y] | ||
private int exactDivide(int x, int y) { x % y = 0 and result = x / y } | ||
|
||
/** Gets the `n`th related location selected in `row`. */ | ||
private TestLocation getRelatedLocation(int row, int n, string element) { | ||
n >= 0 and | ||
exists(int column | | ||
mainQueryResult(row, column, result) and | ||
queryResults(mainResultSet(), row, column + 1, element) | ||
| | ||
result = "(Alert" + sourceSinkTags + ")(\\[(.*)\\])?" | ||
getQueryKind() = "path-problem" and | ||
n = exactDivide(column - 8, 3) | ||
or | ||
getQueryKind() = "problem" and | ||
n = exactDivide(column - 3, 3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's hard to figure out where these numbers come from, can you add an inline explanation to each line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. I added a clarifying comment and noticed a bug, namely that the 8 should have been a 7. There was no |
||
) | ||
} | ||
|
||
private string getAnActiveTag() { | ||
result = ["Alert", "RelatedLocation"] | ||
or | ||
getQueryKind() = "path-problem" and | ||
result = ["Source", "Sink"] | ||
} | ||
|
||
private string getTagRegex() { result = "(" + concat(getAnActiveTag(), "|") + ")(\\[(.*)\\])?" } | ||
|
||
/** | ||
* A configuration for matching `// $ Source=foo` comments against actual | ||
* path-problem sources. | ||
|
@@ -878,6 +889,18 @@ module TestPostProcessing { | |
not hasPathProblemSink(row, location, _, _) | ||
} | ||
|
||
private predicate hasRelatedLocation( | ||
int row, TestLocation location, string element, string tag | ||
) { | ||
getQueryKind() = ["problem", "path-problem"] and | ||
location = getRelatedLocation(row, _, element) and | ||
hasExpectationWithValue("RelatedLocation", _) and | ||
tag = "RelatedLocation" and | ||
not hasAlert(row, location, _, _) and | ||
not hasPathProblemSource(row, location, _, _, _) and | ||
not hasPathProblemSink(row, location, _, _) | ||
} | ||
|
||
/** | ||
* Gets the expected value for result row `row`, if any. This value must | ||
* match the value at the corresponding path-problem source (if it is | ||
|
@@ -899,6 +922,8 @@ module TestPostProcessing { | |
hasPathProblemSink(row, location, element, tag) | ||
or | ||
hasAlert(row, location, element, tag) | ||
or | ||
hasRelatedLocation(row, location, element, tag) | ||
| | ||
not exists(getValue(row)) and value = "" | ||
or | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see
n
being used outside of the predicate, so maybe the predicate can be simplified?