Skip to content

Commit d7b852f

Browse files
committed
use count aggregate to count
1 parent 0f82370 commit d7b852f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstructionCustomizations.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ module UnsafeShellCommandConstruction {
4848
* Gets the number of occurrences of "/" in `path`.
4949
*/
5050
bindingset[path]
51-
private int countSlashes(string path) {
52-
not exists(path.indexOf("/")) and result = 0
53-
or
54-
result = max(int n | exists(path.indexOf("/", n, 0)) | n)
55-
}
51+
private int countSlashes(string path) { result = count(path.splitAt("/")) - 1 }
5652

5753
/**
5854
* Gets the topmost package.json that appears in the project.
@@ -63,7 +59,7 @@ module UnsafeShellCommandConstruction {
6359
private PackageJSON getTopmostPackageJSON() {
6460
result =
6561
min(PackageJSON j |
66-
countSlashes(j.getFile().getRelativePath()) <= 2
62+
countSlashes(j.getFile().getRelativePath()) <= 3
6763
|
6864
j order by countSlashes(j.getFile().getRelativePath())
6965
)

0 commit comments

Comments
 (0)