@@ -850,16 +850,28 @@ pub(crate) fn suspicious_function_call(checker: &mut Checker, call: &ExprCall) {
850850 // MarkSafe
851851 [ "django" , "utils" , "safestring" | "html" , "mark_safe" ] => Some ( SuspiciousMarkSafeUsage . into ( ) ) ,
852852 // URLOpen (`Request`)
853- [ "urllib" , "request" , "Request" ] |
853+ [ "urllib" , "request" , "Request" ] |
854854 [ "six" , "moves" , "urllib" , "request" , "Request" ] => {
855- // If the `url` argument is a string literal, allow `http` and `https` schemes.
855+ // If the `url` argument is a string literal or an f string , allow `http` and `https` schemes.
856856 if call. arguments . args . iter ( ) . all ( |arg| !arg. is_starred_expr ( ) ) && call. arguments . keywords . iter ( ) . all ( |keyword| keyword. arg . is_some ( ) ) {
857- if let Some ( Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) ) = & call. arguments . find_argument ( "url" , 0 ) {
857+ match call. arguments . find_argument ( "url" , 0 ) {
858+ // If the `url` argument is a string literal, allow `http` and `https` schemes.
859+ Some ( Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) ) => {
858860 let url = value. to_str ( ) . trim_start ( ) ;
859861 if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
860862 return None ;
861863 }
862-
864+ } ,
865+ // If the `url` argument is an f-string literal, allow `http` and `https` schemes.
866+ Some ( Expr :: FString ( ast:: ExprFString { value, .. } ) ) => {
867+ if let Some ( ast:: FStringElement :: Literal ( ast:: FStringLiteralElement { value, .. } ) ) = value. elements ( ) . next ( ) {
868+ let url = value. trim_start ( ) ;
869+ if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
870+ return None ;
871+ }
872+ }
873+ } ,
874+ _ => { }
863875 }
864876 }
865877 Some ( SuspiciousURLOpenUsage . into ( ) )
@@ -868,27 +880,52 @@ pub(crate) fn suspicious_function_call(checker: &mut Checker, call: &ExprCall) {
868880 [ "urllib" , "request" , "urlopen" | "urlretrieve" ] |
869881 [ "six" , "moves" , "urllib" , "request" , "urlopen" | "urlretrieve" ] => {
870882 if call. arguments . args . iter ( ) . all ( |arg| !arg. is_starred_expr ( ) ) && call. arguments . keywords . iter ( ) . all ( |keyword| keyword. arg . is_some ( ) ) {
871- if let Some ( arg ) = & call. arguments . find_argument ( "url" , 0 ) {
883+ match call. arguments . find_argument ( "url" , 0 ) {
872884 // If the `url` argument is a string literal, allow `http` and `https` schemes.
873- if let Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) = arg {
885+ Some ( Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) ) => {
874886 let url = value. to_str ( ) . trim_start ( ) ;
875887 if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
876888 return None ;
877889 }
878- }
890+ } ,
891+
892+ // If the `url` argument is an f-string literal, allow `http` and `https` schemes.
893+ Some ( Expr :: FString ( ast:: ExprFString { value, .. } ) ) => {
894+ if let Some ( ast:: FStringElement :: Literal ( ast:: FStringLiteralElement { value, .. } ) ) = value. elements ( ) . next ( ) {
895+ let url = value. trim_start ( ) ;
896+ if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
897+ return None ;
898+ }
899+ }
900+ } ,
879901
880902 // If the `url` argument is a `urllib.request.Request` object, allow `http` and `https` schemes.
881- if let Expr :: Call ( ExprCall { func, arguments, .. } ) = arg {
903+ Some ( Expr :: Call ( ExprCall { func, arguments, .. } ) ) => {
882904 if checker. semantic ( ) . resolve_qualified_name ( func. as_ref ( ) ) . is_some_and ( |name| name. segments ( ) == [ "urllib" , "request" , "Request" ] ) {
883- if let Some ( Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) ) = arguments. find_argument ( "url" , 0 ) {
905+ match arguments. find_argument ( "url" , 0 ) {
906+ // If the `url` argument is a string literal, allow `http` and `https` schemes.
907+ Some ( Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) ) => {
884908 let url = value. to_str ( ) . trim_start ( ) ;
885909 if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
886910 return None ;
887911 }
888-
912+ } ,
913+
914+ // If the `url` argument is an f-string literal, allow `http` and `https` schemes.
915+ Some ( Expr :: FString ( ast:: ExprFString { value, .. } ) ) => {
916+ if let Some ( ast:: FStringElement :: Literal ( ast:: FStringLiteralElement { value, .. } ) ) = value. elements ( ) . next ( ) {
917+ let url = value. trim_start ( ) ;
918+ if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
919+ return None ;
920+ }
921+ }
922+ } ,
923+ _ => { }
889924 }
890925 }
891- }
926+ } ,
927+
928+ _ => { }
892929 }
893930 }
894931 Some ( SuspiciousURLOpenUsage . into ( ) )
0 commit comments