Skip to content

Commit daad2e1

Browse files
committed
Swift: Use regexp for function name.
1 parent 560aa43 commit daad2e1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

swift/ql/lib/codeql/swift/elements/decl/Function.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ private import codeql.swift.elements.decl.Method
66
*/
77
class Function extends Generated::Function, Callable {
88
override string toString() { result = this.getName() }
9+
10+
/**
11+
* Gets the name of this function, without the argument list. For example
12+
* a function with name `myFunction(arg:)` has short name `myFunction`.
13+
*/
14+
string getShortName() {
15+
// match as many characters as possible that are not `(`.
16+
// (`*+` is possessive matching)
17+
result = this.getName().regexpCapture("([^(]*+).*", 1)
18+
}
919
}
1020

1121
/**

swift/ql/lib/codeql/swift/security/SensitiveExprs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private class SensitiveFunction extends Function {
102102
string name; // name of the function, not including the argument list.
103103

104104
SensitiveFunction() {
105-
name = this.getName().splitAt("(", 0) and
105+
name = this.getShortName() and
106106
name.regexpMatch(sensitiveType.getRegexp())
107107
}
108108

0 commit comments

Comments
 (0)