Skip to content

Commit f3bb0a6

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

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

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
)

0 commit comments

Comments
 (0)