Skip to content

Commit 2fb19f0

Browse files
committed
refactor into a single regular expression with two capture groups
1 parent f6f8bbd commit 2fb19f0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

javascript/ql/src/semmle/javascript/frameworks/ServerLess.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ private module ServerLess {
6363
private predicate hasServerlessHandler(File file, string func) {
6464
exists(File ymlFile, string handler, string codeURI, string fileName |
6565
hasServerlessHandler(ymlFile, handler, codeURI) and
66-
// Captures everything right of the dot in `handler`. E.g. if `handler` is "index.foo" then `func` is "foo".
67-
func = handler.regexpCapture(".*\\.(.*)", 1) and
68-
// Captures everything left of the dot in `handler`. E.g. if `handler` is "index.foo" then `fileName` is "index".
69-
fileName = handler.regexpCapture("([^.]+).*", 1)
66+
// Splits a `handler` into two components. The `fileName` to the left of the dot, and the `func` to the right.
67+
// E.g. if `handler` is "index.foo", then `fileName` is "index" and `func` is "foo".
68+
exists(string pattern | pattern = "(.*)\\.(.*)" |
69+
fileName = handler.regexpCapture(pattern, 1) and
70+
func = handler.regexpCapture(pattern, 2)
71+
)
7072
|
7173
file.getAbsolutePath() =
7274
ymlFile.getParentContainer().getAbsolutePath() + "/" +

0 commit comments

Comments
 (0)