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

Skip to content

Commit 4b845d5

Browse files
Move test cases to their own directory to avoid conflict
1 parent 9f4da65 commit 4b845d5

5 files changed

Lines changed: 130 additions & 130 deletions

File tree

Lines changed: 102 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,104 @@
1+
package generatedtest;
2+
3+
import java.util.regex.Matcher;
14
import java.util.regex.Pattern;
25

3-
class Test {
4-
static String[] regs = {
5-
"[A-Z\\d]++",
6-
"\\Q hello world [ *** \\Q ) ( \\E",
7-
"[\\Q hi ] \\E]",
8-
"[]]",
9-
"[^]]",
10-
"[abc[defg]]",
11-
"[abc&&[\\W\\p{Lower}\\P{Space}\\N{degree sign}]]\\b7\\b{g}8",
12-
"\\cA",
13-
"\\c(",
14-
"\\c\\(ab)",
15-
"(?>hi)(?<name>hell*?o*+)123\\k<name>",
16-
"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,}+",
17-
"(?i)(?=a)(?!b)(?<=c)(?<!d)",
18-
"a||b|c(d|e|)f|g",
19-
"\\018\\033\\0377\\0777\u1337",
20-
21-
};
22-
23-
void test() {
24-
for (int i = 0; i < regs.length; i++) {
25-
Pattern.compile(regs[i]);
26-
}
27-
}
28-
}
6+
// Test case generated by GenerateFlowTestCase.ql
7+
public class Test {
8+
9+
private final String str_pattern = "\\$\\{(.*)\\}";
10+
private final Pattern pattern = Pattern.compile(str_pattern);
11+
12+
Object source() { return null; }
13+
void sink(Object o) { }
14+
15+
public void test() throws Exception {
16+
17+
{
18+
// "java.util.regex;Matcher;false;group;;;Argument[-1];ReturnValue;taint"
19+
String out = null;
20+
String in = (String) source();
21+
Matcher m = pattern.matcher(in);
22+
out = m.group("foo");
23+
sink(out); // $ hasTaintFlow
24+
}
25+
{
26+
// "java.util.regex;Matcher;false;group;;;Argument[-1];ReturnValue;taint"
27+
String out = null;
28+
String in = (String) source();
29+
Matcher m = pattern.matcher(in);
30+
out = m.group();
31+
sink(out); // $ hasTaintFlow
32+
}
33+
{
34+
// "java.util.regex;Matcher;false;group;;;Argument[-1];ReturnValue;taint"
35+
String out = null;
36+
String in = (String) source();
37+
Matcher m = pattern.matcher(in);
38+
out = m.group(0);
39+
sink(out); // $ hasTaintFlow
40+
}
41+
{
42+
// "java.util.regex;Matcher;false;replaceAll;;;Argument[-1];ReturnValue;taint"
43+
String out = null;
44+
String in = (String) source();
45+
Matcher m = pattern.matcher(in);
46+
out = m.replaceAll("foo");
47+
sink(out); // $ hasTaintFlow
48+
}
49+
{
50+
// "java.util.regex;Matcher;false;replaceAll;;;Argument[0];ReturnValue;taint"
51+
String out = null;
52+
String in = (String) source();
53+
Matcher m = pattern.matcher("foo");
54+
out = m.replaceAll(in);
55+
sink(out); // $ hasTaintFlow
56+
}
57+
{
58+
// "java.util.regex;Matcher;false;replaceFirst;;;Argument[-1];ReturnValue;taint"
59+
String out = null;
60+
String in = (String) source();
61+
Matcher m = pattern.matcher(in);
62+
out = m.replaceFirst("foo");
63+
sink(out); // $ hasTaintFlow
64+
}
65+
{
66+
// "java.util.regex;Matcher;false;replaceFirst;;;Argument[0];ReturnValue;taint"
67+
String out = null;
68+
String in = (String) source();
69+
Matcher m = pattern.matcher("foo");
70+
out = m.replaceFirst(in);
71+
sink(out); // $ hasTaintFlow
72+
}
73+
{
74+
// "java.util.regex;Pattern;false;matcher;;;Argument[0];ReturnValue;taint"
75+
Matcher out = null;
76+
CharSequence in = (CharSequence)source();
77+
out = pattern.matcher(in);
78+
sink(out); // $ hasTaintFlow
79+
}
80+
{
81+
// "java.util.regex;Pattern;false;quote;;;Argument[0];ReturnValue;taint"
82+
String out = null;
83+
String in = (String)source();
84+
out = Pattern.quote(in);
85+
sink(out); // $ hasTaintFlow
86+
}
87+
{
88+
// "java.util.regex;Pattern;false;split;;;Argument[0];ReturnValue;taint"
89+
String[] out = null;
90+
CharSequence in = (CharSequence)source();
91+
out = pattern.split(in);
92+
sink(out); // $ hasTaintFlow
93+
}
94+
{
95+
// "java.util.regex;Pattern;false;split;;;Argument[0];ReturnValue;taint"
96+
String[] out = null;
97+
CharSequence in = (CharSequence)source();
98+
out = pattern.split(in, 0);
99+
sink(out); // $ hasTaintFlow
100+
}
101+
102+
}
103+
104+
}

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

Lines changed: 0 additions & 104 deletions
This file was deleted.

java/ql/test/library-tests/regex/RegexParseTests.expected renamed to java/ql/test/library-tests/regex/parser/RegexParseTests.expected

File renamed without changes.

java/ql/test/library-tests/regex/RegexParseTests.ql renamed to java/ql/test/library-tests/regex/parser/RegexParseTests.ql

File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.regex.Pattern;
2+
3+
class Test {
4+
static String[] regs = {
5+
"[A-Z\\d]++",
6+
"\\Q hello world [ *** \\Q ) ( \\E",
7+
"[\\Q hi ] \\E]",
8+
"[]]",
9+
"[^]]",
10+
"[abc[defg]]",
11+
"[abc&&[\\W\\p{Lower}\\P{Space}\\N{degree sign}]]\\b7\\b{g}8",
12+
"\\cA",
13+
"\\c(",
14+
"\\c\\(ab)",
15+
"(?>hi)(?<name>hell*?o*+)123\\k<name>",
16+
"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,}+",
17+
"(?i)(?=a)(?!b)(?<=c)(?<!d)",
18+
"a||b|c(d|e|)f|g",
19+
"\\018\\033\\0377\\0777\u1337",
20+
21+
};
22+
23+
void test() {
24+
for (int i = 0; i < regs.length; i++) {
25+
Pattern.compile(regs[i]);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)