Java: Fix for multiple parse mode flags.

This commit is contained in:
Geoffrey White
2023-07-20 11:41:10 +01:00
parent 32c10885d4
commit 369f88beda
2 changed files with 14 additions and 7 deletions

View File

@@ -472,12 +472,19 @@ abstract class RegexString extends StringLiteral {
)
}
private predicate flagGroupStart(int start, int end, string c) {
private predicate flagGroupStart(int start, int end) {
this.isGroupStart(start) and
this.getChar(start + 1) = "?" and
end = start + 3 and
c = this.getChar(start + 2) and
c in ["i", "m", "s", "u", "x", "U"]
this.getChar(start + 2) in ["i", "m", "s", "u", "x", "U"] and
end = start + 2
}
private predicate flagGroup(int start, int end, string c) {
exists(int inStart, int inEnd |
this.flagGroupStart(start, inStart) and
this.groupContents(start, end, inStart, inEnd) and
this.getChar([inStart .. inEnd - 1]) = c
)
}
/**
@@ -485,7 +492,7 @@ abstract class RegexString extends StringLiteral {
* it is defined by a prefix.
*/
string getModeFromPrefix() {
exists(string c | this.flagGroupStart(_, _, c) |
exists(string c | this.flagGroup(_, _, c) |
c = "i" and result = "IGNORECASE"
or
c = "m" and result = "MULTILINE"
@@ -540,7 +547,7 @@ abstract class RegexString extends StringLiteral {
private predicate groupStart(int start, int end) {
this.nonCapturingGroupStart(start, end)
or
this.flagGroupStart(start, end, _)
this.flagGroupStart(start, end)
or
this.namedGroupStart(start, end)
or