JS: Include anchor direction in message

This commit is contained in:
Asger F
2019-10-22 12:03:02 +01:00
parent 3e952cf564
commit 2b151cd587
2 changed files with 50 additions and 48 deletions

View File

@@ -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"
)
}