Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb0c1ed

Browse files
committed
feat(SC2016,SC2033,SC2067,SC2150,SC2156): checkfind -ok/-okdir
fix#3332
1 parentc5514e1 commiteb0c1ed

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

‎src/ShellCheck/Analytics.hs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,9 @@ checkFindExec _ cmd@(T_SimpleCommand _ _ t@(h:r)) | cmd `isCommand` "find" = do
768768
when v (mapM_ warnFor$ fromWord w)
769769
case getLiteralString wof
770770
Just"-exec"-> broken rTrue
771-
Just"-execdir"-> broken rTrue
771+
Just"-execdir"-> broken rTrue-- n.b. -execdir ;/+ is not defined in POSIX
772+
Just"-ok"-> broken rTrue-- n.b. -ok + is not defined in POSIX
773+
Just"-okdir"-> broken rTrue-- n.b. -okdir ;/+ is not defined in POSIX
772774
Just"+"-> broken rFalse
773775
Just";"-> broken rFalse
774776
_-> broken r v
@@ -1142,7 +1144,7 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
11421144

11431145
getFindCommand (T_SimpleCommand _ _words)=
11441146
let list=map getLiteralStringwords
1145-
cmd=dropWhile (\x-> x/=Just"-exec"&& x/=Just"-execdir") list
1147+
cmd=dropWhile (\x-> x`notElem`mapJust["-exec","-execdir","-ok","-okdir"]) list
11461148
in
11471149
case cmdof
11481150
(flag:cmd:rest)-> fromMaybe"find" cmd
@@ -2387,7 +2389,7 @@ checkFunctionsUsedExternally params t =
23872389
_->[]
23882390
where
23892391
firstNonFlag=take1$ dropFlags argAndString
2390-
findExecFlags= ["-exec","-execdir","-ok"]
2392+
findExecFlags= ["-exec","-execdir","-ok","-okdir"]
23912393
dropFlags=dropWhile (\x->"-"`isPrefixOf`fst x)
23922394

23932395
functionsAndAliases=Map.union (functions t) (aliases t)

‎src/ShellCheck/Checks/Commands.hs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ checkFindExecWithSingleArgument = CommandCheck (Basename "find") (f . arguments)
470470
termS<- getLiteralString term
471471
let cmdS= getLiteralStringDef"" arg
472472

473-
guard$ execS`elem` ["-exec","-execdir"]&& termS`elem` [";","+"]
473+
guard$ execS`elem` ["-exec","-execdir","-ok","-okdir"]&& termS`elem` [";","+"]
474474
guard$ cmdS`matches` commandRegex
475-
return$ warn (getId exec)2150"-exec does not invoke a shell. Rewrite or use-execsh -c .. ."
475+
return$ warn (getId exec)2150(execS++" does not invoke a shell. Rewrite or use"++ execS++"sh -c .. .")
476476
check _=Nothing
477477
commandRegex= mkRegex"[ |;]"
478478

@@ -505,7 +505,7 @@ checkUnusedEchoEscapes = CommandCheck (Basename "echo") f
505505

506506
prop_checkInjectableFindSh1= verify checkInjectableFindSh"find . -exec sh -c 'echo {}'\\;"
507507
prop_checkInjectableFindSh2= verify checkInjectableFindSh"find . -execdir bash -c 'rm\"{}\"' ';'"
508-
prop_checkInjectableFindSh3= verifyNot checkInjectableFindSh"find . -exec sh -c 'rm\"$@\"' _ {}\\;"
508+
prop_checkInjectableFindSh3= verifyNot checkInjectableFindSh"find . -ok sh -c 'rm\"$@\"' _ {}\\;"
509509
checkInjectableFindSh=CommandCheck (Basename"find") (check. arguments)
510510
where
511511
check args=do
@@ -519,7 +519,7 @@ checkInjectableFindSh = CommandCheck (Basename "find") (check . arguments)
519519
match (p:tests) args
520520

521521
pattern= [
522-
(`elem` ["-exec","-execdir"]),
522+
(`elem` ["-exec","-execdir","-ok","-okdir"]),
523523
(`elem` ["sh","bash","dash","ksh"]),
524524
(=="-c")
525525
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp