Allow string percent formatting in os.getenv (#3518)

This commit is contained in:
Charlie Marsh 2023-03-14 14:27:21 -04:00 committed by GitHub
parent 1b738f88c4
commit c50d6da8b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -8,5 +8,5 @@ os.getenv("AA", "GOOD")
os.getenv("AA", f"GOOD")
os.getenv("AA", "GOOD" + "BAD")
os.getenv("AA", "GOOD" + 1)
os.getenv("AA", "GOOD %s" % "BAD")
os.getenv("B", Z)

View file

@ -49,6 +49,7 @@ fn is_valid_default(expr: &Expr) -> bool {
return true;
}
// Allow string concatenation.
if let ExprKind::BinOp {
left,
right,
@ -58,6 +59,16 @@ fn is_valid_default(expr: &Expr) -> bool {
return is_valid_default(left) && is_valid_default(right);
}
// Allow string formatting.
if let ExprKind::BinOp {
left,
op: Operator::Mod,
..
} = &expr.node
{
return is_valid_default(left);
}
// Otherwise, the default must be a string or `None`.
matches!(
expr.node,

View file

@ -46,6 +46,7 @@ fn is_valid_key(expr: &Expr) -> bool {
return true;
}
// Allow string concatenation.
if let ExprKind::BinOp {
left,
right,
@ -55,6 +56,16 @@ fn is_valid_key(expr: &Expr) -> bool {
return is_valid_key(left) && is_valid_key(right);
}
// Allow string formatting.
if let ExprKind::BinOp {
left,
op: Operator::Mod,
..
} = &expr.node
{
return is_valid_key(left);
}
// Otherwise, the default must be a string.
matches!(
expr.node,