Skip to content

Commit 931c683

Browse files
authored
Use regex for case-insensitive string comparisons
This is slightly more efficient.
1 parent c427f8f commit 931c683

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module Twirp {
8080
exists(ServiceInterfaceType i, PointerType p, TypeEntity te |
8181
p.implements(i) and
8282
this = p.getBaseType() and
83-
this.getName().toLowerCase() = i.getName().toLowerCase() + ["protobuf", "json"] + "client" and
83+
this.getName().regexpMatch("(?i)" + i.getName() + ["(protobuf|json)" + "client") and
8484
te.getType() = this and
8585
te.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
8686
)
@@ -94,7 +94,7 @@ module Twirp {
9494
ServiceServerType() {
9595
exists(ServiceInterfaceType i, TypeEntity te |
9696
this.implements(i) and
97-
this.getName().toLowerCase() = i.getName().toLowerCase() + "server" and
97+
this.getName().regexpMatch("(?i)" + i.getName() + "server") and
9898
te.getType() = this and
9999
te.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
100100
)
@@ -107,7 +107,7 @@ module Twirp {
107107
class ClientConstructor extends Function {
108108
ClientConstructor() {
109109
exists(ServiceClientType c |
110-
this.getName().toLowerCase() = "new" + c.getName().toLowerCase() and
110+
this.getName().regexpMatch("(?i)new" + c.getName()) and
111111
this.getParameterType(0) instanceof StringType and
112112
this.getParameterType(1).getName() = "HTTPClient" and
113113
this.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
@@ -123,7 +123,7 @@ module Twirp {
123123
class ServerConstructor extends Function {
124124
ServerConstructor() {
125125
exists(ServiceServerType c, ServiceInterfaceType i |
126-
this.getName().toLowerCase() = "new" + c.getName().toLowerCase() and
126+
this.getName().regexpMatch("(?i)new" + c.getName()) and
127127
this.getParameterType(0) = i.getNamedType() and
128128
this.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
129129
)

0 commit comments

Comments
 (0)