mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Java: Split literals tests
This allows changing individual tests in the future without having to adjust the expected output of all other tests.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package stringLiterals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StringLiterals {
|
||||
String[] strings = {
|
||||
"",
|
||||
"hello,\tworld",
|
||||
"hello,\u0009world",
|
||||
"\u0061", // 'a'
|
||||
"\0",
|
||||
"\uFFFF",
|
||||
"\ufFfF",
|
||||
"\"",
|
||||
"\'",
|
||||
"\n",
|
||||
"\\",
|
||||
"test \123", // octal escape sequence for 'S'
|
||||
"\1234", // octal escape followed by '4'
|
||||
"\0000", // octal escape \000 followed by '0'
|
||||
"\u0061567", // escape sequence for 'a' followed by "567"
|
||||
"\u1234567", // '\u1234' followed by "567"
|
||||
"\uaBcDeF\u0aB1", // '\uABCD' followed by "eF" followed by '\u0AB1'
|
||||
"\uD800\uDC00", // surrogate pair
|
||||
"\uDBFF\uDFFF", // U+10FFFF
|
||||
// Unpaired surrogates
|
||||
"\uD800",
|
||||
"\uDC00",
|
||||
"hello\uD800hello\uDC00world", // malformed surrogates
|
||||
// Using Unicode escapes (which are handled during pre-processing)
|
||||
"\u005C\u0022", // escaped double quote ("\"")
|
||||
\u0022\u0061\u0022, // "a"
|
||||
};
|
||||
|
||||
// The concatenation (`+`) is not a string literal
|
||||
String[] stringConcatenation = {
|
||||
// CodeQL erroneously reports this as one literal, see https://github.com/github/codeql/issues/5469
|
||||
"hello" + "world",
|
||||
null + "a",
|
||||
"a" + null,
|
||||
"a" + 1,
|
||||
1 + "a",
|
||||
"a" + true,
|
||||
true + "a",
|
||||
"a" + 'b',
|
||||
'b' + "a",
|
||||
};
|
||||
|
||||
Object[] nonStringLiterals = {
|
||||
'a',
|
||||
'"',
|
||||
true,
|
||||
null,
|
||||
0,
|
||||
File.pathSeparator
|
||||
};
|
||||
|
||||
String nonLiteral;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
| StringLiterals.java:7:3:7:4 | "" | | |
|
||||
| StringLiterals.java:8:3:8:17 | "hello,\\tworld" | hello,\tworld | hello,\tworld |
|
||||
| StringLiterals.java:9:3:9:21 | "hello,\\u0009world" | hello,\tworld | hello,\tworld |
|
||||
| StringLiterals.java:10:3:10:10 | "\\u0061" | a | a |
|
||||
| StringLiterals.java:11:3:11:6 | "\\0" | \u0000 | \u0000 |
|
||||
| StringLiterals.java:12:3:12:10 | "\\uFFFF" | \uffff | \uffff |
|
||||
| StringLiterals.java:13:3:13:10 | "\\ufFfF" | \uffff | \uffff |
|
||||
| StringLiterals.java:14:3:14:6 | "\\"" | " | " |
|
||||
| StringLiterals.java:15:3:15:6 | "\\'" | ' | ' |
|
||||
| StringLiterals.java:16:3:16:6 | "\\n" | \n | \n |
|
||||
| StringLiterals.java:17:3:17:6 | "\\\\" | \\ | \\ |
|
||||
| StringLiterals.java:18:3:18:13 | "test \\123" | test S | test S |
|
||||
| StringLiterals.java:19:3:19:9 | "\\1234" | S4 | S4 |
|
||||
| StringLiterals.java:20:3:20:9 | "\\0000" | \u00000 | \u00000 |
|
||||
| StringLiterals.java:21:3:21:13 | "\\u0061567" | a567 | a567 |
|
||||
| StringLiterals.java:22:3:22:13 | "\\u1234567" | \u1234567 | \u1234567 |
|
||||
| StringLiterals.java:23:3:23:18 | "\\uaBcDeF\\u0aB1" | \uabcdeF\u0ab1 | \uabcdeF\u0ab1 |
|
||||
| StringLiterals.java:24:3:24:16 | "\\uD800\\uDC00" | \ud800\udc00 | \ud800\udc00 |
|
||||
| StringLiterals.java:25:3:25:16 | "\\uDBFF\\uDFFF" | \udbff\udfff | \udbff\udfff |
|
||||
| StringLiterals.java:27:3:27:10 | "\\uD800" | \ufffd | \ufffd |
|
||||
| StringLiterals.java:28:3:28:10 | "\\uDC00" | \ufffd | \ufffd |
|
||||
| StringLiterals.java:29:3:29:31 | "hello\\uD800hello\\uDC00world" | hello\ufffdhello\ufffdworld | hello\ufffdhello\ufffdworld |
|
||||
| StringLiterals.java:31:3:31:16 | "\\u005C\\u0022" | " | " |
|
||||
| StringLiterals.java:32:8:32:20 | 2\\u0061\\u0022 | a | a |
|
||||
| StringLiterals.java:38:3:38:19 | "hello" + "world" | helloworld | helloworld |
|
||||
| StringLiterals.java:39:10:39:12 | "a" | a | a |
|
||||
| StringLiterals.java:40:3:40:5 | "a" | a | a |
|
||||
| StringLiterals.java:41:3:41:5 | "a" | a | a |
|
||||
| StringLiterals.java:42:7:42:9 | "a" | a | a |
|
||||
| StringLiterals.java:43:3:43:5 | "a" | a | a |
|
||||
| StringLiterals.java:44:10:44:12 | "a" | a | a |
|
||||
| StringLiterals.java:45:3:45:5 | "a" | a | a |
|
||||
| StringLiterals.java:46:9:46:11 | "a" | a | a |
|
||||
@@ -0,0 +1,5 @@
|
||||
import semmle.code.java.Expr
|
||||
|
||||
from StringLiteral lit
|
||||
where lit.getFile().(CompilationUnit).fromSource()
|
||||
select lit, lit.getValue(), lit.getRepresentedString()
|
||||
Reference in New Issue
Block a user