mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
JS: Include anchor direction in message
This commit is contained in:
@@ -99,7 +99,7 @@ predicate containsLetters(RegExpTerm term) {
|
||||
* parsed as `(^a)|(b)|(c)`.
|
||||
*/
|
||||
predicate isInterestingSemiAnchoredRegExpString(RegExpPatternSource src, string msg) {
|
||||
exists(RegExpAlt root, RegExpSequence anchoredTerm |
|
||||
exists(RegExpAlt root, RegExpSequence anchoredTerm, string direction |
|
||||
root = src.getRegExpTerm() and
|
||||
not containsInteriorAnchor(root) and
|
||||
not isEmpty(root.getAChild()) and
|
||||
@@ -108,15 +108,17 @@ predicate isInterestingSemiAnchoredRegExpString(RegExpPatternSource src, string
|
||||
anchoredTerm = root.getChild(0) and
|
||||
anchoredTerm.getChild(0) instanceof RegExpCaret and
|
||||
not containsLeadingPseudoAnchor(root.getChild([ 1 .. root.getNumChild() - 1 ])) and
|
||||
containsLetters(root.getChild([ 1 .. root.getNumChild() - 1 ]))
|
||||
containsLetters(root.getChild([ 1 .. root.getNumChild() - 1 ])) and
|
||||
direction = "beginning"
|
||||
or
|
||||
anchoredTerm = root.getLastChild() and
|
||||
anchoredTerm.getLastChild() instanceof RegExpDollar and
|
||||
not containsTrailingPseudoAnchor(root.getChild([ 0 .. root.getNumChild() - 2 ])) and
|
||||
containsLetters(root.getChild([ 0 .. root.getNumChild() - 2 ]))
|
||||
containsLetters(root.getChild([ 0 .. root.getNumChild() - 2 ])) and
|
||||
direction = "end"
|
||||
) and
|
||||
msg = "Misleading operator precedence. The subexpression '" + anchoredTerm.getRawValue() +
|
||||
"' is anchored, but the other parts of this regular expression are not"
|
||||
"' is anchored at the " + direction + ", but the other parts of this regular expression are not"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user