mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #2856 from esbena/js/fix-RegExp-getPredecessor-getSuccessor
Approved by max-schaefer
This commit is contained in:
@@ -75,25 +75,22 @@ class RegExpTerm extends Locatable, @regexpterm {
|
||||
|
||||
/** Gets the regular expression term that is matched (textually) before this one, if any. */
|
||||
RegExpTerm getPredecessor() {
|
||||
exists(RegExpSequence seq, int i |
|
||||
seq.getChild(i) = this and
|
||||
seq.getChild(i - 1) = result
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
result = parent.(RegExpSequence).previousElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).previousElement(this)) and
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getPredecessor()
|
||||
)
|
||||
or
|
||||
result = getParent().(RegExpTerm).getPredecessor()
|
||||
}
|
||||
|
||||
/** Gets the regular expression term that is matched (textually) after this one, if any. */
|
||||
RegExpTerm getSuccessor() {
|
||||
exists(RegExpSequence seq, int i |
|
||||
seq.getChild(i) = this and
|
||||
seq.getChild(i + 1) = result
|
||||
)
|
||||
or
|
||||
exists(RegExpTerm parent |
|
||||
parent = getParent() and
|
||||
not parent instanceof RegExpSubPattern
|
||||
|
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
result = parent.(RegExpSequence).nextElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).nextElement(this)) and
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getSuccessor()
|
||||
)
|
||||
}
|
||||
@@ -313,6 +310,19 @@ class RegExpSequence extends RegExpTerm, @regexp_seq {
|
||||
or
|
||||
result = getChild(i).getConstantValue() + getConstantValue(i+1)
|
||||
}
|
||||
|
||||
/** Gets the element preceding `element` in this sequence. */
|
||||
RegExpTerm previousElement(RegExpTerm element) {
|
||||
element = nextElement(result)
|
||||
}
|
||||
|
||||
/** Gets the element following `element` in this sequence. */
|
||||
RegExpTerm nextElement(RegExpTerm element) {
|
||||
exists(int i |
|
||||
element = this.getChild(i) and
|
||||
result = this.getChild(i + 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
| tst.js:2:2:2:2 | a | tst.js:2:3:2:5 | (b) |
|
||||
| tst.js:2:2:2:2 | a | tst.js:2:4:2:4 | b |
|
||||
| tst.js:3:2:3:3 | ab | tst.js:3:4:3:6 | (c) |
|
||||
| tst.js:3:2:3:3 | ab | tst.js:3:5:3:5 | c |
|
||||
| tst.js:4:2:4:2 | a | tst.js:4:3:4:6 | (bc) |
|
||||
| tst.js:4:2:4:2 | a | tst.js:4:4:4:5 | bc |
|
||||
| tst.js:5:2:5:2 | a | tst.js:5:3:5:8 | (b[c]) |
|
||||
| tst.js:5:2:5:2 | a | tst.js:5:4:5:4 | b |
|
||||
| tst.js:5:2:5:2 | a | tst.js:5:4:5:7 | b[c] |
|
||||
| tst.js:5:4:5:4 | b | tst.js:5:5:5:7 | [c] |
|
||||
| tst.js:5:4:5:4 | b | tst.js:5:6:5:6 | c |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:3:6:9 | (b\|[b]) |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:4:6:4 | b |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:4:6:8 | b\|[b] |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:6:6:8 | [b] |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:7:6:7 | b |
|
||||
| tst.js:7:2:7:2 | a | tst.js:7:3:7:10 | ([b][c]) |
|
||||
| tst.js:7:2:7:2 | a | tst.js:7:4:7:6 | [b] |
|
||||
| tst.js:7:2:7:2 | a | tst.js:7:4:7:9 | [b][c] |
|
||||
| tst.js:7:2:7:2 | a | tst.js:7:5:7:5 | b |
|
||||
| tst.js:7:4:7:6 | [b] | tst.js:7:7:7:9 | [c] |
|
||||
| tst.js:7:4:7:6 | [b] | tst.js:7:8:7:8 | c |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:3:8:13 | (b\|[b]\|[b]) |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:4:8:4 | b |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:4:8:12 | b\|[b]\|[b] |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:6:8:8 | [b] |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:7:8:7 | b |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:10:8:12 | [b] |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:11:8:11 | b |
|
||||
| tst.js:11:2:11:4 | (a) | tst.js:11:5:11:5 | b |
|
||||
| tst.js:12:2:12:4 | (a) | tst.js:12:5:12:6 | bc |
|
||||
| tst.js:13:2:13:5 | (ab) | tst.js:13:6:13:6 | c |
|
||||
| tst.js:14:2:14:7 | ([a]b) | tst.js:14:8:14:8 | c |
|
||||
| tst.js:14:3:14:5 | [a] | tst.js:14:6:14:6 | b |
|
||||
| tst.js:16:2:16:9 | ([a][b]) | tst.js:16:10:16:10 | c |
|
||||
| tst.js:16:3:16:5 | [a] | tst.js:16:6:16:8 | [b] |
|
||||
| tst.js:16:3:16:5 | [a] | tst.js:16:7:16:7 | b |
|
||||
| tst.js:17:2:17:12 | ([a]\|[a]\|a) | tst.js:17:13:17:13 | b |
|
||||
@@ -0,0 +1,5 @@
|
||||
import javascript
|
||||
|
||||
from RegExpTerm pred, RegExpTerm succ
|
||||
where pred = succ.getPredecessor()
|
||||
select pred, succ
|
||||
@@ -0,0 +1,34 @@
|
||||
| tst.js:2:2:2:2 | a | tst.js:2:3:2:5 | (b) |
|
||||
| tst.js:3:2:3:3 | ab | tst.js:3:4:3:6 | (c) |
|
||||
| tst.js:4:2:4:2 | a | tst.js:4:3:4:6 | (bc) |
|
||||
| tst.js:5:2:5:2 | a | tst.js:5:3:5:8 | (b[c]) |
|
||||
| tst.js:5:4:5:4 | b | tst.js:5:5:5:7 | [c] |
|
||||
| tst.js:6:2:6:2 | a | tst.js:6:3:6:9 | (b\|[b]) |
|
||||
| tst.js:7:2:7:2 | a | tst.js:7:3:7:10 | ([b][c]) |
|
||||
| tst.js:7:4:7:6 | [b] | tst.js:7:7:7:9 | [c] |
|
||||
| tst.js:7:5:7:5 | b | tst.js:7:7:7:9 | [c] |
|
||||
| tst.js:8:2:8:2 | a | tst.js:8:3:8:13 | (b\|[b]\|[b]) |
|
||||
| tst.js:11:2:11:4 | (a) | tst.js:11:5:11:5 | b |
|
||||
| tst.js:11:3:11:3 | a | tst.js:11:5:11:5 | b |
|
||||
| tst.js:12:2:12:4 | (a) | tst.js:12:5:12:6 | bc |
|
||||
| tst.js:12:3:12:3 | a | tst.js:12:5:12:6 | bc |
|
||||
| tst.js:13:2:13:5 | (ab) | tst.js:13:6:13:6 | c |
|
||||
| tst.js:13:3:13:4 | ab | tst.js:13:6:13:6 | c |
|
||||
| tst.js:14:2:14:7 | ([a]b) | tst.js:14:8:14:8 | c |
|
||||
| tst.js:14:3:14:5 | [a] | tst.js:14:6:14:6 | b |
|
||||
| tst.js:14:3:14:6 | [a]b | tst.js:14:8:14:8 | c |
|
||||
| tst.js:14:4:14:4 | a | tst.js:14:6:14:6 | b |
|
||||
| tst.js:14:6:14:6 | b | tst.js:14:8:14:8 | c |
|
||||
| tst.js:16:2:16:9 | ([a][b]) | tst.js:16:10:16:10 | c |
|
||||
| tst.js:16:3:16:5 | [a] | tst.js:16:6:16:8 | [b] |
|
||||
| tst.js:16:3:16:8 | [a][b] | tst.js:16:10:16:10 | c |
|
||||
| tst.js:16:4:16:4 | a | tst.js:16:6:16:8 | [b] |
|
||||
| tst.js:16:6:16:8 | [b] | tst.js:16:10:16:10 | c |
|
||||
| tst.js:16:7:16:7 | b | tst.js:16:10:16:10 | c |
|
||||
| tst.js:17:2:17:12 | ([a]\|[a]\|a) | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:3:17:5 | [a] | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:3:17:11 | [a]\|[a]\|a | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:4:17:4 | a | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:7:17:9 | [a] | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:8:17:8 | a | tst.js:17:13:17:13 | b |
|
||||
| tst.js:17:11:17:11 | a | tst.js:17:13:17:13 | b |
|
||||
@@ -0,0 +1,5 @@
|
||||
import javascript
|
||||
|
||||
from RegExpTerm pred, RegExpTerm succ
|
||||
where succ = pred.getSuccessor()
|
||||
select pred, succ
|
||||
@@ -0,0 +1,17 @@
|
||||
/ab/;
|
||||
/a(b)/;
|
||||
/ab(c)/;
|
||||
/a(bc)/;
|
||||
/a(b[c])/;
|
||||
/a(b|[b])/;
|
||||
/a([b][c])/;
|
||||
/a(b|[b]|[b])/;
|
||||
|
||||
/ab/;
|
||||
/(a)b/;
|
||||
/(a)bc/;
|
||||
/(ab)c/;
|
||||
/([a]b)c/;
|
||||
/([a]|a)|b/;
|
||||
/([a][b])c/;
|
||||
/([a]|[a]|a)b/;
|
||||
Reference in New Issue
Block a user