forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateCharacterInCharacterClass.ql
More file actions
36 lines (33 loc) · 1.13 KB
/
DuplicateCharacterInCharacterClass.ql
File metadata and controls
36 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @name Duplicate character in character class
* @description If a character class in a regular expression contains the same character twice, this may
* indicate a bug.
* @kind problem
* @problem.severity warning
* @id js/regex/duplicate-in-character-class
* @tags reliability
* correctness
* regular-expressions
* @precision very-high
*/
import javascript
/**
* Holds if `cc` is the `i`th constant inside character class `recc` that matches the character `val`.
* Indexing is 1-based.
*/
predicate constantInCharacterClass(RegExpCharacterClass recc, int i, RegExpConstant cc, string val) {
cc =
rank[i](RegExpConstant cc2, int j |
cc2 = recc.getChild(j) and cc2.isCharacter() and cc2.getValue() = val
|
cc2 order by j
)
}
from RegExpCharacterClass recc, RegExpConstant first, RegExpConstant repeat, int rnk, string val
where
constantInCharacterClass(recc, 1, first, val) and
constantInCharacterClass(recc, rnk, repeat, val) and
rnk > 1 and
recc.isPartOfRegExpLiteral()
select first, "Character '" + first + "' is repeated $@ in the same character class.", repeat,
"here"