-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLocations.ql
More file actions
27 lines (24 loc) · 1.03 KB
/
Locations.ql
File metadata and controls
27 lines (24 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import python
import semmle.python.regexp.RegexTreeView::RegexTreeView
import utils.test.InlineExpectationsTest
private import semmle.python.dataflow.new.internal.PrintNode
module RegexLocationTest implements TestSig {
string getARelevantTag() { result = "location" }
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(location.getFile().getRelativePath()) and
exists(Call compile, RegExpTerm t, int line, int column |
// All the tested regexes are inside a call to `compile`
compile.getAnArg() = t.getRegex() and
t.toString() = "[this]" and
t.hasLocationInfo(_, line, column, _, _)
|
// put the annotation on the start line of the call to `compile`
location = compile.getFunc().getLocation() and
element = t.toString() and
// show the (relative) line and column for the fragment
value = (line - location.getStartLine()).toString() + ":" + column.toString() and
tag = "location"
)
}
}
import MakeTest<RegexLocationTest>