Skip to content

Commit b13f118

Browse files
authored
Merge pull request #20054 from aschackmull/java/fixup-control-char-query
Java: Restrict results to source literals.
2 parents 16e9e8e + 9e87095 commit b13f118

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

java/ql/src/Violations of Best Practice/SpecialCharactersInLiterals/NonExplicitControlAndWhitespaceCharsInLiterals.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ReservedUnicodeInLiteral extends Literal {
2323

2424
ReservedUnicodeInLiteral() {
2525
not this instanceof CharacterLiteral and
26+
this.getCompilationUnit().fromSource() and
2627
exists(int codePoint |
2728
this.getLiteral().codePointAt(indexStart) = codePoint and
2829
(
@@ -45,6 +46,9 @@ where
4546
literal.getIndexStart() = charIndex and
4647
literal.getLiteral().codePointAt(charIndex) = codePoint and
4748
not literal.getEnclosingCallable() instanceof LikelyTestMethod and
49+
// Kotlin extraction doesn't preserve the literal value so we can't distinguish
50+
// between control characters and their escaped versions, so we exclude Kotlin
51+
// to avoid false positives.
4852
not literal.getFile().isKotlinSourceFile()
4953
select literal,
5054
"Literal value contains control or non-printable whitespace character(s) starting with Unicode code point "

0 commit comments

Comments
 (0)