Skip to content

Commit ebd7875

Browse files
committed
JS: Add regression test
1 parent fd2e848 commit ebd7875

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

javascript/ql/test/query-tests/Security/CWE-020/IncorrectSuffixCheck.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
| tst.js:67:32:67:71 | x.index ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1010
| tst.js:76:25:76:57 | index = ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1111
| tst.js:80:10:80:57 | x.index ... th + 1) | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
12+
| tst.js:94:49:94:112 | x.lastI ... .length | This suffix check is missing a length comparison to correctly handle lastIndexOf returning -1. |
13+
| tst.js:98:49:98:112 | x.lastI ... .length | This suffix check is missing a length comparison to correctly handle lastIndexOf returning -1. |

javascript/ql/test/query-tests/Security/CWE-020/tst.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ function withIndexOfCheckLowerEq(x, y) {
8989
let index = x.indexOf(y);
9090
return !(index <= -1) && index === x.length - y.length - 1; // OK
9191
}
92+
93+
function lastIndexNeqMinusOne(x) {
94+
return x.lastIndexOf("example.com") !== -1 && x.lastIndexOf("example.com") === x.length - "example.com".length; // OK
95+
}
96+
97+
function lastIndexEqMinusOne(x) {
98+
return x.lastIndexOf("example.com") === -1 || x.lastIndexOf("example.com") === x.length - "example.com".length; // OK
99+
}

0 commit comments

Comments
 (0)