JS: Fix some FPs in IncorrectSuffixCheck

This commit is contained in:
Asger F
2019-05-13 08:54:07 +01:00
parent 649979de3e
commit 9293010e4c
2 changed files with 20 additions and 0 deletions

View File

@@ -139,6 +139,16 @@ class UnsafeIndexOfComparison extends EqualityTest {
not test.isInclusive() and
value = -1
)
) and
// Check for indexOf being <0, or <=-1
not exists(RelationalComparison test |
test.getLesserOperand() = indexOf.getAnEquivalentIndexOfCall().getAUse() and
exists(int value | value = test.getGreaterOperand().getIntValue() |
value < 0
or
not test.isInclusive() and
value = 0
)
)
}

View File

@@ -79,3 +79,13 @@ function withIndexOfCheckBad(x, y) {
function plus(x, y) {
return x.indexOf("." + y) === x.length - (y.length + 1); // NOT OK
}
function withIndexOfCheckLower(x, y) {
let index = x.indexOf(y);
return !(index < 0) && index === x.length - y.length - 1; // OK
}
function withIndexOfCheckLowerEq(x, y) {
let index = x.indexOf(y);
return !(index <= -1) && index === x.length - y.length - 1; // OK
}