Skip to content

Commit 844193d

Browse files
author
Alvaro Muñoz
committed
use regexp to capture generated file names
1 parent 1d0e80c commit 844193d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

go/ql/lib/semmle/go/frameworks/Twirp.qll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ module Twirp {
1212
*/
1313
class ProtobufGeneratedFile extends File {
1414
ProtobufGeneratedFile() {
15-
exists(string name, File t |
16-
this.getBaseName() = name + ".pb.go" and
17-
this.getParentContainer() = t.getParentContainer() and
18-
t.getBaseName() = name + ".twirp.go"
15+
exists(string prefix, File f |
16+
prefix = this.getBaseName().regexpCapture("^(.*)\\.pb\\.go$", 1) and
17+
this.getParentContainer() = f.getParentContainer() and
18+
f.getBaseName() = prefix + ".twirp.go"
1919
)
2020
}
2121
}
@@ -27,10 +27,10 @@ module Twirp {
2727
*/
2828
class ServicesGeneratedFile extends File {
2929
ServicesGeneratedFile() {
30-
exists(string name, File t |
31-
this.getBaseName() = name + ".twirp.go" and
32-
this.getParentContainer() = t.getParentContainer() and
33-
t.getBaseName() = name + ".pb.go"
30+
exists(string prefix, File f |
31+
prefix = this.getBaseName().regexpCapture("^(.*)\\.twirp\\.go$", 1) and
32+
this.getParentContainer() = f.getParentContainer() and
33+
f.getBaseName() = prefix + ".pb.go"
3434
)
3535
}
3636
}
@@ -160,7 +160,6 @@ module Twirp {
160160
}
161161
}
162162

163-
164163
/**
165164
* A request coming to the service handler.
166165
*/

0 commit comments

Comments
 (0)