Consider find -exec when warning about vars in single quotes.

This commit is contained in:
Vidar Holen 2014-10-12 14:00:17 -07:00
parent a69e27b774
commit 1a0e208cc3
1 changed files with 16 additions and 1 deletions

View File

@ -956,6 +956,8 @@ prop_checkSingleQuotedVariables5 = verifyNot checkSingleQuotedVariables "trap 'e
prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'" prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'"
prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'" prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'"
prop_checkSingleQuotedVariables7 = verifyNot checkSingleQuotedVariables "PS1='$PWD \\$ '" prop_checkSingleQuotedVariables7 = verifyNot checkSingleQuotedVariables "PS1='$PWD \\$ '"
prop_checkSingleQuotedVariables8 = verify checkSingleQuotedVariables "find . -exec echo '$1' {} +"
prop_checkSingleQuotedVariables9 = verifyNot checkSingleQuotedVariables "find . -exec awk '{print $1}' {} \\;"
checkSingleQuotedVariables params t@(T_SingleQuoted id s) = checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
when (s `matches` re) $ when (s `matches` re) $
if "sed" == commandName if "sed" == commandName
@ -967,7 +969,10 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
"Expressions don't expand in single quotes, use double quotes for that." "Expressions don't expand in single quotes, use double quotes for that."
commandName = fromMaybe "" $ do commandName = fromMaybe "" $ do
cmd <- getClosestCommand parents t cmd <- getClosestCommand parents t
getCommandBasename cmd name <- getCommandBasename cmd
if name == "find"
then return $ getFindCommand cmd
else return name
isProbablyOk = isProbablyOk =
any isOkAssignment (take 3 $ getPath parents t) any isOkAssignment (take 3 $ getPath parents t)
@ -992,6 +997,16 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
re = mkRegex "\\$[{(0-9a-zA-Z_]" re = mkRegex "\\$[{(0-9a-zA-Z_]"
sedContra = mkRegex "\\$[dpsaic]($|[^a-zA-Z])" sedContra = mkRegex "\\$[dpsaic]($|[^a-zA-Z])"
getFindCommand (T_SimpleCommand _ _ words) =
let list = map getLiteralString words
cmd = dropWhile (\x -> x /= Just "-exec" && x /= Just "-execdir") list
in
case cmd of
(flag:cmd:rest) -> fromMaybe "find" cmd
_ -> "find"
getFindCommand (T_Redirecting _ _ cmd) = getFindCommand cmd
getFindCommand _ = "find"
checkSingleQuotedVariables _ _ = return () checkSingleQuotedVariables _ _ = return ()