mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
JS: Fix some FPs in IncorrectSuffixCheck
This commit is contained in:
@@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user