Don't warn when $(seq) is used unquoted.
This commit is contained in:
parent
e3bef9dc97
commit
50084c06c5
|
@ -215,6 +215,19 @@ getCommandName t =
|
|||
T_Annotation _ _ t -> getCommandName t
|
||||
otherwise -> Nothing
|
||||
|
||||
-- If a command substitution is a single command, get its name.
|
||||
-- $(date +%s) = Just "date"
|
||||
getCommandNameFromExpansion :: Token -> Maybe String
|
||||
getCommandNameFromExpansion t =
|
||||
case t of
|
||||
T_DollarExpansion _ [c] -> extract c
|
||||
T_Backticked _ [c] -> extract c
|
||||
T_DollarBraceCommandExpansion _ [c] -> extract c
|
||||
otherwise -> Nothing
|
||||
where
|
||||
extract (T_Pipeline _ _ [cmd]) = getCommandName cmd
|
||||
extract _ = Nothing
|
||||
|
||||
-- Get the basename of a token representing a command
|
||||
getCommandBasename = liftM basename . getCommandName
|
||||
where
|
||||
|
@ -238,8 +251,8 @@ isOnlyRedirection t =
|
|||
|
||||
isFunction t = case t of T_Function {} -> True; _ -> False
|
||||
|
||||
-- Get the list of commands from tokens that contain them, such as
|
||||
-- the body of while loops and if statements.
|
||||
-- Get the lists of commands from tokens that contain them, such as
|
||||
-- the body of while loops or branches of if statements.
|
||||
getCommandSequences t =
|
||||
case t of
|
||||
T_Script _ _ cmds -> [cmds]
|
||||
|
@ -252,6 +265,7 @@ getCommandSequences t =
|
|||
T_IfExpression _ thens elses -> map snd thens ++ [elses]
|
||||
otherwise -> []
|
||||
|
||||
-- Get a list of names of associative arrays
|
||||
getAssociativeArrays t =
|
||||
nub . execWriter $ doAnalysis f t
|
||||
where
|
||||
|
|
|
@ -765,6 +765,7 @@ prop_checkUnquotedExpansions4 = verifyNot checkUnquotedExpansions "[[ $(foo) ==
|
|||
prop_checkUnquotedExpansions5 = verifyNot checkUnquotedExpansions "for f in $(cmd); do echo $f; done"
|
||||
prop_checkUnquotedExpansions6 = verifyNot checkUnquotedExpansions "$(cmd)"
|
||||
prop_checkUnquotedExpansions7 = verifyNot checkUnquotedExpansions "cat << foo\n$(ls)\nfoo"
|
||||
prop_checkUnquotedExpansions8 = verifyNot checkUnquotedExpansions "set -- $(seq 1 4)"
|
||||
checkUnquotedExpansions params =
|
||||
check
|
||||
where
|
||||
|
@ -774,9 +775,12 @@ checkUnquotedExpansions params =
|
|||
check _ = return ()
|
||||
tree = parentMap params
|
||||
examine t =
|
||||
unless (isQuoteFree tree t || usedAsCommandName tree t) $
|
||||
unless (shouldBeSplit t || isQuoteFree tree t || usedAsCommandName tree t) $
|
||||
warn (getId t) 2046 "Quote this to prevent word splitting."
|
||||
|
||||
shouldBeSplit t =
|
||||
getCommandNameFromExpansion t == Just "seq"
|
||||
|
||||
|
||||
prop_checkRedirectToSame = verify checkRedirectToSame "cat foo > foo"
|
||||
prop_checkRedirectToSame2 = verify checkRedirectToSame "cat lol | sed -e 's/a/b/g' > lol"
|
||||
|
@ -1030,6 +1034,7 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
|
|||
,"alias"
|
||||
,"sudo" -- covering "sudo sh" and such
|
||||
,"dpkg-query"
|
||||
,"jq" -- could also check that user provides --arg
|
||||
]
|
||||
|| "awk" `isSuffixOf` commandName
|
||||
|| "perl" `isPrefixOf` commandName
|
||||
|
|
Loading…
Reference in New Issue