mirror of
https://github.com/github/codeql.git
synced 2026-04-24 08:15:14 +02:00
JS: Add test for missing getALocalSource flow for rest pattern
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
function t1() {
|
||||
const { ...rest } = source('t1.1');
|
||||
rest; // $ MISSING: getALocalSource=rest
|
||||
}
|
||||
|
||||
function t2() {
|
||||
const [ ...rest ] = source('t2.1');
|
||||
rest; // $ MISSING: getALocalSource=rest
|
||||
}
|
||||
|
||||
function t3() {
|
||||
const { p1, ...rest } = source('t3.1');
|
||||
p1; // $ getALocalSource=p1
|
||||
rest; // $ MISSING: getALocalSource=rest
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
| rest-pattern.js:13:5:13:6 | p1 | p1 |
|
||||
30
javascript/ql/test/library-tests/GetALocalSource/test.ql
Normal file
30
javascript/ql/test/library-tests/GetALocalSource/test.ql
Normal file
@@ -0,0 +1,30 @@
|
||||
import javascript
|
||||
|
||||
string nodeName(DataFlow::SourceNode node) {
|
||||
result = node.getAstNode().(VarRef).getName()
|
||||
or
|
||||
result = node.getAstNode().(PropertyPattern).getName()
|
||||
or
|
||||
result = node.getAstNode().(PropAccess).getPropertyName()
|
||||
or
|
||||
exists(DataFlow::InvokeNode invoke |
|
||||
node = invoke and
|
||||
invoke.getCalleeName() = "source" and
|
||||
result = invoke.getArgument(0).getStringValue()
|
||||
)
|
||||
}
|
||||
|
||||
bindingset[node1, node2]
|
||||
pragma[inline_late]
|
||||
predicate sameLine(DataFlow::Node node1, DataFlow::Node node2) {
|
||||
node1.getLocation().getFile() = node2.getLocation().getFile() and
|
||||
node1.getLocation().getStartLine() = node2.getLocation().getStartLine()
|
||||
}
|
||||
|
||||
query predicate getALocalSource(DataFlow::Node node, string name) {
|
||||
exists(DataFlow::SourceNode sn |
|
||||
sn = node.getALocalSource() and
|
||||
name = nodeName(sn) and
|
||||
not sameLine(node, sn)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
query: test.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
Reference in New Issue
Block a user