Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc10952

Browse files
Simplify octal handling
1 parent 9e88c67 commit bc10952

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

java/ql/lib/semmle/code/java/regex/regex.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,14 @@ abstract class RegexString extends StringLiteral {
280280
or
281281
// octal value \0o, \0oo, or \0ooo. Max of 0377.
282282
this.getChar(start + 1) = "0" and
283-
end in [start + 3 .. start + 5] and
284-
forall(int i | i in [start + 1 .. end - 1] | this.isOctal(i)) and
285-
(end = start + 5 implies this.getChar(start + 2) <= "3") and
286-
not (
287-
end < start + 5 and
288-
this.isOctal(end) and
289-
(end = start + 4 implies this.getChar(start + 2) <= "3")
283+
this.isOctal(start + 2) and
284+
(
285+
if this.isOctal(start + 3)
286+
then
287+
if this.isOctal(start + 4) and this.getChar(start + 2) in ["0", "1", "2", "3"]
288+
then end = start + 5
289+
else end = start + 4
290+
else end = start + 3
290291
)
291292
or
292293
// 16-bit hex value \uhhhh

java/ql/test/library-tests/regex/RegexParseTests.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,10 @@ parseFailures
130130
| Test.java:18:18:18:18 | e | [RegExpConstant,RegExpNormalChar] |
131131
| Test.java:18:20:18:20 | f | [RegExpConstant,RegExpNormalChar] |
132132
| Test.java:18:22:18:22 | g | [RegExpConstant,RegExpNormalChar] |
133+
| Test.java:19:10:19:12 | \\01 | [RegExpConstant,RegExpEscape] |
134+
| Test.java:19:10:19:27 | \\018\\033\\0377\\0777 | [RegExpSequence] |
135+
| Test.java:19:13:19:13 | 8 | [RegExpConstant,RegExpNormalChar] |
136+
| Test.java:19:14:19:17 | \\033 | [RegExpConstant,RegExpEscape] |
137+
| Test.java:19:18:19:22 | \\0377 | [RegExpConstant,RegExpEscape] |
138+
| Test.java:19:23:19:26 | \\077 | [RegExpConstant,RegExpEscape] |
139+
| Test.java:19:27:19:27 | 7 | [RegExpConstant,RegExpNormalChar] |

java/ql/test/library-tests/regex/Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Test {
1515
"(?>hi)(?<name>hell*?o*+)123\\k<name>",
1616
"a+b*c?d{2}e{3,4}f{,5}g{6,}h+?i*?j??k{7}?l{8,9}?m{,10}?n{11,}?o++p*+q?+r{12}+s{13,14}+t{,15}+u{16,}+",
1717
"(?i)(?=a)(?!b)(?<=c)(?<!d)",
18-
"a|b|c(d|e)f|g"
18+
"a|b|c(d|e)f|g",
19+
"\\018\\033\\0377\\0777"
1920
};
2021

2122
void test() {

0 commit comments

Comments
 (0)