Python: Replace '.prefix'/'.suffix' with '.matches'.

This commit is contained in:
Mathias Vorreiter Pedersen
2021-10-13 13:19:58 +01:00
parent f3bb0a676e
commit a80860cdc6
7 changed files with 8 additions and 8 deletions

View File

@@ -29,7 +29,7 @@ private predicate pyxl_tag(Call c, string name) {
}
class PyxlHtmlTag extends PyxlTag {
PyxlHtmlTag() { this.getPyxlTagName().prefix(2) = "x_" }
PyxlHtmlTag() { this.getPyxlTagName().matches("x\\_%") }
string getTagName() { result = this.getPyxlTagName().suffix(2) }

View File

@@ -33,7 +33,7 @@ class WsgiEnvironment extends TaintKind {
(
text = "QUERY_STRING" or
text = "PATH_INFO" or
text.prefix(5) = "HTTP_"
text.matches("HTTP\\_%")
)
)
}

View File

@@ -88,7 +88,7 @@ class CredentialSink extends TaintSink {
CredentialSink() {
exists(string name |
name.regexpMatch(getACredentialRegex()) and
not name.suffix(name.length() - 4) = "file"
not name.matches("%file")
|
any(FunctionValue func).getNamedArgumentForCall(_, name) = this
or

View File

@@ -141,7 +141,7 @@ predicate builtin_object_consistency(string clsname, string problem, string what
or
not exists(o.toString()) and
problem = "no toString" and
not exists(string name | name.prefix(7) = "_semmle" | py_special_objects(o, name)) and
not exists(string name | name.matches("\\_semmle%") | py_special_objects(o, name)) and
not o = unknownValue()
)
}

View File

@@ -11,7 +11,7 @@ class HasTypeFact extends CustomPointsToOriginFact {
exists(FunctionObject func, string name |
func.getACall() = this and
name = func.getName() and
name.prefix("has_type_".length()) = "has_type_"
name.matches("has\\_type\\_%")
)
}
@@ -19,7 +19,7 @@ class HasTypeFact extends CustomPointsToOriginFact {
exists(FunctionObject func, string name |
func.getACall() = this and
name = func.getName() and
name.prefix("has_type_".length()) = "has_type_"
name.matches("has\\_type\\_%")
|
cls.getName() = name.suffix("has_type_".length())
) and

View File

@@ -104,7 +104,7 @@ predicate ssa_consistency(string clsname, string problem, string what) {
or
exists(EssaDefinition def |
clsname = def.getAQlClass() and
clsname.prefix(4) = "Essa" and
clsname.matches("Essa%") and
what = " at " + def.getLocation() and
problem = "not covered by Python-specific subclass."
)

View File

@@ -28,7 +28,7 @@ class SimpleSource extends TaintSource {
predicate visit_call(CallNode call, FunctionObject func) {
exists(AttrNode attr, ClassObject cls, string name |
name.prefix(6) = "visit_" and
name.matches("visit\\_%") and
func = cls.lookupAttribute(name) and
attr.getObject("visit").refersTo(_, cls, _) and
attr = call.getFunction()