mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #6869 from MathiasVP/fix-prefix/suffix-equality
Java/JS/Python: Replace '.prefix'/'.suffix' with '.matches'
This commit is contained in:
@@ -37,7 +37,7 @@ predicate isGigaSpacesEventMethod(Method eventMethod) {
|
||||
class GigaSpacesSpaceIdGetterMethod extends Method {
|
||||
GigaSpacesSpaceIdGetterMethod() {
|
||||
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceId") and
|
||||
getName().prefix(3) = "get"
|
||||
getName().matches("get%")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class GigaSpacesSpaceIdSetterMethod extends Method {
|
||||
GigaSpacesSpaceIdSetterMethod() {
|
||||
exists(GigaSpacesSpaceIdGetterMethod getterMethod |
|
||||
getterMethod.getDeclaringType() = getDeclaringType() and
|
||||
getName().prefix(3) = "set"
|
||||
getName().matches("set%")
|
||||
|
|
||||
getterMethod.getName().suffix(3) = getName().suffix(3)
|
||||
)
|
||||
@@ -62,6 +62,6 @@ class GigaSpacesSpaceIdSetterMethod extends Method {
|
||||
class GigaSpacesSpaceRoutingMethod extends Method {
|
||||
GigaSpacesSpaceRoutingMethod() {
|
||||
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceRouting") and
|
||||
getName().prefix(3) = "get"
|
||||
getName().matches("get%")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class SpringProfileExpr extends string {
|
||||
* A Spring profile expression that begins with "!", indicating a negated expression.
|
||||
*/
|
||||
class NotSpringProfileExpr extends SpringProfileExpr {
|
||||
NotSpringProfileExpr() { this.prefix(1) = "!" }
|
||||
NotSpringProfileExpr() { this.matches("!%") }
|
||||
|
||||
/**
|
||||
* Gets the profile described in this profile expression.
|
||||
|
||||
@@ -129,7 +129,7 @@ class Pom extends ProtoPom {
|
||||
* occurs by considering the properties defined by this project or an ancestor project.
|
||||
*/
|
||||
string resolvePlaceholder(string name) {
|
||||
if name.prefix(8) = "project."
|
||||
if name.matches("project.%")
|
||||
then
|
||||
exists(PomElement p |
|
||||
p = getProjectProperty() and
|
||||
|
||||
@@ -727,7 +727,7 @@ module NodeJSLib {
|
||||
result = getParameter(1).getARhs()
|
||||
}
|
||||
|
||||
override predicate isSync() { "Sync" = methodName.suffix(methodName.length() - 4) }
|
||||
override predicate isSync() { methodName.matches("%Sync") }
|
||||
|
||||
override DataFlow::Node getOptionsArg() {
|
||||
not result.getALocalSource() instanceof DataFlow::FunctionNode and // looks like callback
|
||||
|
||||
@@ -107,9 +107,7 @@ private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::I
|
||||
*/
|
||||
bindingset[name]
|
||||
private boolean getSync(string name) {
|
||||
if name.suffix(name.length() - 4) = "Sync" or name.suffix(name.length() - 4) = "sync"
|
||||
then result = true
|
||||
else result = false
|
||||
if name.matches("%Sync") or name.matches("%sync") then result = true else result = false
|
||||
}
|
||||
|
||||
private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::InvokeNode {
|
||||
|
||||
@@ -303,14 +303,11 @@ module PrettyPrintCatCall {
|
||||
bindingset[str]
|
||||
private string createSimplifiedStringConcat(string str) {
|
||||
// Remove an initial ""+ (e.g. in `""+file`)
|
||||
if str.prefix(5) = "\"\" + "
|
||||
if str.matches("\"\" + %")
|
||||
then result = str.suffix(5)
|
||||
else
|
||||
// prettify `${newpath}` to just newpath
|
||||
if
|
||||
str.prefix(3) = "`${" and
|
||||
str.suffix(str.length() - 2) = "}`" and
|
||||
not str.suffix(3).matches("%{%")
|
||||
if str.matches("`${%") and str.matches("%}`") and not str.suffix(3).matches("%{%")
|
||||
then result = str.prefix(str.length() - 2).suffix(3)
|
||||
else result = str
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class AsyncSentinelCall extends DataFlow::CallNode {
|
||||
exists(DataFlow::FunctionNode node | node.getAstNode() = asyncCallee |
|
||||
// manual models
|
||||
exists(string memberName |
|
||||
not "Sync" = memberName.suffix(memberName.length() - 4) and
|
||||
not memberName.matches("%Sync") and
|
||||
this = NodeJSLib::FS::moduleMember(memberName).getACall() and
|
||||
node = this.getCallback([1 .. 2])
|
||||
)
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class WsgiEnvironment extends TaintKind {
|
||||
(
|
||||
text = "QUERY_STRING" or
|
||||
text = "PATH_INFO" or
|
||||
text.prefix(5) = "HTTP_"
|
||||
text.matches("HTTP\\_%")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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."
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user