Skip to content

Commit 47a85bb

Browse files
authored
Merge pull request github#6869 from MathiasVP/fix-prefix/suffix-equality
Java/JS/Python: Replace '.prefix'/'.suffix' with '.matches'
2 parents a5ab0b9 + 4991301 commit 47a85bb

File tree

14 files changed

+18
-23
lines changed

14 files changed

+18
-23
lines changed

java/ql/lib/semmle/code/java/frameworks/gigaspaces/GigaSpaces.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ predicate isGigaSpacesEventMethod(Method eventMethod) {
3737
class GigaSpacesSpaceIdGetterMethod extends Method {
3838
GigaSpacesSpaceIdGetterMethod() {
3939
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceId") and
40-
getName().prefix(3) = "get"
40+
getName().matches("get%")
4141
}
4242
}
4343

@@ -48,7 +48,7 @@ class GigaSpacesSpaceIdSetterMethod extends Method {
4848
GigaSpacesSpaceIdSetterMethod() {
4949
exists(GigaSpacesSpaceIdGetterMethod getterMethod |
5050
getterMethod.getDeclaringType() = getDeclaringType() and
51-
getName().prefix(3) = "set"
51+
getName().matches("set%")
5252
|
5353
getterMethod.getName().suffix(3) = getName().suffix(3)
5454
)
@@ -62,6 +62,6 @@ class GigaSpacesSpaceIdSetterMethod extends Method {
6262
class GigaSpacesSpaceRoutingMethod extends Method {
6363
GigaSpacesSpaceRoutingMethod() {
6464
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceRouting") and
65-
getName().prefix(3) = "get"
65+
getName().matches("get%")
6666
}
6767
}

java/ql/lib/semmle/code/java/frameworks/spring/SpringProfile.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SpringProfileExpr extends string {
3737
* A Spring profile expression that begins with "!", indicating a negated expression.
3838
*/
3939
class NotSpringProfileExpr extends SpringProfileExpr {
40-
NotSpringProfileExpr() { this.prefix(1) = "!" }
40+
NotSpringProfileExpr() { this.matches("!%") }
4141

4242
/**
4343
* Gets the profile described in this profile expression.

java/ql/lib/semmle/code/xml/MavenPom.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Pom extends ProtoPom {
129129
* occurs by considering the properties defined by this project or an ancestor project.
130130
*/
131131
string resolvePlaceholder(string name) {
132-
if name.prefix(8) = "project."
132+
if name.matches("project.%")
133133
then
134134
exists(PomElement p |
135135
p = getProjectProperty() and

javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ module NodeJSLib {
727727
result = getParameter(1).getARhs()
728728
}
729729

730-
override predicate isSync() { "Sync" = methodName.suffix(methodName.length() - 4) }
730+
override predicate isSync() { methodName.matches("%Sync") }
731731

732732
override DataFlow::Node getOptionsArg() {
733733
not result.getALocalSource() instanceof DataFlow::FunctionNode and // looks like callback

javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::I
107107
*/
108108
bindingset[name]
109109
private boolean getSync(string name) {
110-
if name.suffix(name.length() - 4) = "Sync" or name.suffix(name.length() - 4) = "sync"
111-
then result = true
112-
else result = false
110+
if name.matches("%Sync") or name.matches("%sync") then result = true else result = false
113111
}
114112

115113
private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::InvokeNode {

javascript/ql/lib/semmle/javascript/security/UselessUseOfCat.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,11 @@ module PrettyPrintCatCall {
303303
bindingset[str]
304304
private string createSimplifiedStringConcat(string str) {
305305
// Remove an initial ""+ (e.g. in `""+file`)
306-
if str.prefix(5) = "\"\" + "
306+
if str.matches("\"\" + %")
307307
then result = str.suffix(5)
308308
else
309309
// prettify `${newpath}` to just newpath
310-
if
311-
str.prefix(3) = "`${" and
312-
str.suffix(str.length() - 2) = "}`" and
313-
not str.suffix(3).matches("%{%")
310+
if str.matches("`${%") and str.matches("%}`") and not str.suffix(3).matches("%{%")
314311
then result = str.prefix(str.length() - 2).suffix(3)
315312
else result = str
316313
}

javascript/ql/src/Security/CWE-730/ServerCrash.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class AsyncSentinelCall extends DataFlow::CallNode {
104104
exists(DataFlow::FunctionNode node | node.getAstNode() = asyncCallee |
105105
// manual models
106106
exists(string memberName |
107-
not "Sync" = memberName.suffix(memberName.length() - 4) and
107+
not memberName.matches("%Sync") and
108108
this = NodeJSLib::FS::moduleMember(memberName).getACall() and
109109
node = this.getCallback([1 .. 2])
110110
)

python/ql/lib/semmle/python/templates/PyxlTags.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private predicate pyxl_tag(Call c, string name) {
2929
}
3030

3131
class PyxlHtmlTag extends PyxlTag {
32-
PyxlHtmlTag() { this.getPyxlTagName().prefix(2) = "x_" }
32+
PyxlHtmlTag() { this.getPyxlTagName().matches("x\\_%") }
3333

3434
string getTagName() { result = this.getPyxlTagName().suffix(2) }
3535

python/ql/lib/semmle/python/web/Http.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WsgiEnvironment extends TaintKind {
3333
(
3434
text = "QUERY_STRING" or
3535
text = "PATH_INFO" or
36-
text.prefix(5) = "HTTP_"
36+
text.matches("HTTP\\_%")
3737
)
3838
)
3939
}

python/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class CredentialSink extends TaintSink {
8888
CredentialSink() {
8989
exists(string name |
9090
name.regexpMatch(getACredentialRegex()) and
91-
not name.suffix(name.length() - 4) = "file"
91+
not name.matches("%file")
9292
|
9393
any(FunctionValue func).getNamedArgumentForCall(_, name) = this
9494
or

0 commit comments

Comments
 (0)