Skip to content

Commit a80860c

Browse files
committed
Python: Replace '.prefix'/'.suffix' with '.matches'.
1 parent f3bb0a6 commit a80860c

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

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

python/ql/src/analysis/Consistency.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ predicate builtin_object_consistency(string clsname, string problem, string what
141141
or
142142
not exists(o.toString()) and
143143
problem = "no toString" and
144-
not exists(string name | name.prefix(7) = "_semmle" | py_special_objects(o, name)) and
144+
not exists(string name | name.matches("\\_semmle%") | py_special_objects(o, name)) and
145145
not o = unknownValue()
146146
)
147147
}

python/ql/test/library-tests/PointsTo/customise/test.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class HasTypeFact extends CustomPointsToOriginFact {
1111
exists(FunctionObject func, string name |
1212
func.getACall() = this and
1313
name = func.getName() and
14-
name.prefix("has_type_".length()) = "has_type_"
14+
name.matches("has\\_type\\_%")
1515
)
1616
}
1717

1818
override predicate pointsTo(Object value, ClassObject cls) {
1919
exists(FunctionObject func, string name |
2020
func.getACall() = this and
2121
name = func.getName() and
22-
name.prefix("has_type_".length()) = "has_type_"
22+
name.matches("has\\_type\\_%")
2323
|
2424
cls.getName() = name.suffix("has_type_".length())
2525
) and

python/ql/test/library-tests/PointsTo/new/Consistency.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ predicate ssa_consistency(string clsname, string problem, string what) {
104104
or
105105
exists(EssaDefinition def |
106106
clsname = def.getAQlClass() and
107-
clsname.prefix(4) = "Essa" and
107+
clsname.matches("Essa%") and
108108
what = " at " + def.getLocation() and
109109
problem = "not covered by Python-specific subclass."
110110
)

python/ql/test/library-tests/taint/extensions/ExtensionsLib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SimpleSource extends TaintSource {
2828

2929
predicate visit_call(CallNode call, FunctionObject func) {
3030
exists(AttrNode attr, ClassObject cls, string name |
31-
name.prefix(6) = "visit_" and
31+
name.matches("visit\\_%") and
3232
func = cls.lookupAttribute(name) and
3333
attr.getObject("visit").refersTo(_, cls, _) and
3434
attr = call.getFunction()

0 commit comments

Comments
 (0)