Merge pull request #6869 from MathiasVP/fix-prefix/suffix-equality

Java/JS/Python: Replace '.prefix'/'.suffix' with '.matches'
This commit is contained in:
Mathias Vorreiter Pedersen
2021-10-14 13:47:03 +01:00
committed by GitHub
14 changed files with 18 additions and 23 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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])
)