Files
codeql/python/ql/src/Expressions/UnintentionalImplicitStringConcatenation.ql
Joe Farebrother 5c4548df45 Tag more quality queries.
Excluded for now for uncertainty: incomplete ordering, import deprecated module
2025-06-19 14:06:57 +01:00

35 lines
971 B
Plaintext

/**
* @name Implicit string concatenation in a list
* @description Omitting a comma between strings causes implicit concatenation which is confusing in a list.
* @kind problem
* @tags quality
* maintainability
* readability
* external/cwe/cwe-665
* @problem.severity warning
* @sub-severity high
* @precision high
* @id py/implicit-string-concatenation-in-list
*/
import python
predicate string_const(Expr s) {
s instanceof StringLiteral
or
string_const(s.(BinaryExpr).getLeft()) and string_const(s.(BinaryExpr).getRight())
}
from StringLiteral s
where
// Implicitly concatenated string is in a list and that list contains at least one other string.
exists(List l, Expr other |
not s = other and
l.getAnElt() = s and
l.getAnElt() = other and
string_const(other)
) and
exists(s.getAnImplicitlyConcatenatedPart()) and
not s.isParenthesized()
select s, "Implicit string concatenation. Maybe missing a comma?"