Skip S608 for expressionless f-strings (#17999)

This commit is contained in:
Max Mynter 2025-05-10 12:37:58 +02:00 committed by GitHub
parent cd1d906ffa
commit b765dc48e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View file

@ -166,3 +166,6 @@ query60 = f"""
foo foo
FROM ({user_input}) raw FROM ({user_input}) raw
""" """
# https://github.com/astral-sh/ruff/issues/17967
query61 = f"SELECT * FROM table" # skip expressionless f-strings

View file

@ -100,7 +100,15 @@ pub(crate) fn hardcoded_sql_expression(checker: &Checker, expr: &Expr) {
} }
// f"select * from table where val = {val}" // f"select * from table where val = {val}"
Expr::FString(f_string) => concatenated_f_string(f_string, checker.locator()), Expr::FString(f_string)
if f_string
.value
.f_strings()
.any(|fs| fs.elements.iter().any(ast::FStringElement::is_expression)) =>
{
concatenated_f_string(f_string, checker.locator())
}
_ => return, _ => return,
}; };

View file

@ -601,4 +601,6 @@ S608.py:164:11: S608 Possible SQL injection vector through string-based query co
167 | | FROM ({user_input}) raw 167 | | FROM ({user_input}) raw
168 | | """ 168 | | """
| |___^ S608 | |___^ S608
169 |
170 | # https://github.com/astral-sh/ruff/issues/17967
| |