Skip to content

Commit 74e39a7

Browse files
committed
JS: Add support for RelatedLocation tags
1 parent d94dc5a commit 74e39a7

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

shared/util/codeql/util/test/InlineExpectationsTest.qll

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -779,22 +779,37 @@ module TestPostProcessing {
779779
)
780780
}
781781

782-
private string getTagRegex() {
783-
exists(string sourceSinkTags |
784-
(
785-
getQueryKind() = "problem"
786-
or
787-
not exists(getSourceTag(_)) and
788-
not exists(getSinkTag(_))
789-
) and
790-
sourceSinkTags = ""
791-
or
792-
sourceSinkTags = "|" + getSourceTag(_) + "|" + getSinkTag(_)
782+
bindingset[x, y]
783+
private int exactDivide(int x, int y) { x % y = 0 and result = x / y }
784+
785+
/** Gets the `n`th related location selected in `row`. */
786+
private TestLocation getRelatedLocation(int row, int n, string element) {
787+
n >= 0 and
788+
exists(int column |
789+
mainQueryResult(row, column, result) and
790+
queryResults(mainResultSet(), row, column + 1, element)
793791
|
794-
result = "(Alert" + sourceSinkTags + ")(\\[(.*)\\])?"
792+
getQueryKind() = "path-problem" and
793+
n = exactDivide(column - 8, 3)
794+
or
795+
getQueryKind() = "problem" and
796+
n = exactDivide(column - 3, 3)
795797
)
796798
}
797799

800+
private string getAnActiveTag() {
801+
result = "Alert"
802+
or
803+
getQueryKind() = "path-problem" and
804+
hasExpectationWithValue(["Source", "Sink"], _) and
805+
result = ["Source", "sink"]
806+
or
807+
hasExpectationWithValue("RelatedLocation", _) and
808+
result = "RelatedLocation"
809+
}
810+
811+
private string getTagRegex() { result = "(" + concat(getAnActiveTag(), "|") + ")(\\[(.*)\\])?" }
812+
798813
/**
799814
* A configuration for matching `// $ Source=foo` comments against actual
800815
* path-problem sources.
@@ -878,6 +893,18 @@ module TestPostProcessing {
878893
not hasPathProblemSink(row, location, _, _)
879894
}
880895

896+
private predicate hasRelatedLocation(
897+
int row, TestLocation location, string element, string tag
898+
) {
899+
getQueryKind() = ["problem", "path-problem"] and
900+
location = getRelatedLocation(row, _, element) and
901+
hasExpectationWithValue("RelatedLocation", _) and
902+
tag = "RelatedLocation" and
903+
not hasAlert(row, location, _, _) and
904+
not hasPathProblemSource(row, location, _, _, _) and
905+
not hasPathProblemSink(row, location, _, _)
906+
}
907+
881908
/**
882909
* Gets the expected value for result row `row`, if any. This value must
883910
* match the value at the corresponding path-problem source (if it is
@@ -899,6 +926,8 @@ module TestPostProcessing {
899926
hasPathProblemSink(row, location, element, tag)
900927
or
901928
hasAlert(row, location, element, tag)
929+
or
930+
hasRelatedLocation(row, location, element, tag)
902931
|
903932
not exists(getValue(row)) and value = ""
904933
or

0 commit comments

Comments
 (0)