Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1fa7f8

Browse files
committed
add support for the any argument tokens
1 parent 413d182 commit b1fa7f8

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModelsSpecific.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ API::Node getExtraSuccessorFromNode(API::Node node, AccessPathToken token) {
7272
exists(string name | token.getAnArgument() = name + ":" |
7373
result = node.getKeywordParameter(name)
7474
)
75+
or
76+
token.getAnArgument() = "any" and
77+
result = [node.getParameter(_), node.getKeywordParameter(_)]
78+
or
79+
token.getAnArgument() = "any-named" and
80+
result = node.getKeywordParameter(_)
7581
)
7682
// Some features don't have MaD tokens yet, they would need to be added to API-graphs first.
7783
// - decorators ("DecoratedClass", "DecoratedMember", "DecoratedParameter")
@@ -182,7 +188,7 @@ predicate isExtraValidTokenArgumentInIdentifyingAccessPath(string name, string a
182188
or
183189
name = ["Argument", "Parameter"] and
184190
(
185-
argument = "self"
191+
argument = ["self", "any", "any-named"]
186192
or
187193
argument.regexpMatch("\\w+:") // keyword argument
188194
)

python/ql/test/library-tests/frameworks/data/test.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ isSink
2424
| test.py:33:27:33:29 | ControlFlowNode for two | test-source |
2525
| test.py:33:32:33:36 | ControlFlowNode for three | test-source |
2626
| test.py:57:7:57:12 | ControlFlowNode for ArgPos | test-source |
27+
| test.py:66:17:66:20 | ControlFlowNode for arg1 | test-source |
28+
| test.py:66:23:66:26 | ControlFlowNode for arg2 | test-source |
29+
| test.py:66:34:66:43 | ControlFlowNode for namedThing | test-source |
30+
| test.py:67:34:67:44 | ControlFlowNode for secondNamed | test-source |
2731
isSource
2832
| test.py:3:5:3:15 | ControlFlowNode for getSource() | test-source |
2933
| test.py:9:8:9:14 | ControlFlowNode for alias() | test-source |
@@ -45,6 +49,11 @@ isSource
4549
| test.py:51:8:51:18 | ControlFlowNode for Sub2Class() | test-source |
4650
| test.py:53:7:53:16 | ControlFlowNode for Attribute() | test-source |
4751
| test.py:60:13:60:16 | ControlFlowNode for self | test-source |
52+
| test.py:60:24:60:28 | ControlFlowNode for named | test-source |
53+
| test.py:63:36:63:39 | ControlFlowNode for arg2 | test-source |
54+
| test.py:63:42:63:45 | ControlFlowNode for arg3 | test-source |
55+
| test.py:63:48:63:51 | ControlFlowNode for arg4 | test-source |
56+
| test.py:63:54:63:57 | ControlFlowNode for arg5 | test-source |
4857
syntaxErrors
4958
| Member[foo |
5059
| Member[foo] .Member[bar] |

python/ql/test/library-tests/frameworks/data/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ def foo(self, arg, named=2, otherName=3):
6262

6363
def secondAndAfter(self, arg1, arg2, arg3, arg4, arg5):
6464
pass
65+
66+
ArgPos.anyParam(arg1, arg2, name=namedThing)
67+
ArgPos.anyNamed(arg4, arg5, name=secondNamed)

python/ql/test/library-tests/frameworks/data/test.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Sinks extends ModelInput::SinkModelCsv {
5151
"testlib;;Member[CallFilter].Member[twoOrMore].WithArity[2..].Argument[0..];test-source", //
5252
// testing non-positional arguments
5353
"testlib;;Member[ArgPos].Member[selfThing].Argument[self];test-source", //
54+
// any argument
55+
"testlib;;Member[ArgPos].Member[anyParam].Argument[any];test-source", //
56+
"testlib;;Member[ArgPos].Member[anyNamed].Argument[any-named];test-source", //
5457
]
5558
}
5659
}

0 commit comments

Comments
 (0)