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
|
T_Annotation _ _ t -> getCommandName t
|
||||||
otherwise -> Nothing
|
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
|
-- Get the basename of a token representing a command
|
||||||
getCommandBasename = liftM basename . getCommandName
|
getCommandBasename = liftM basename . getCommandName
|
||||||
where
|
where
|
||||||
|
@ -238,8 +251,8 @@ isOnlyRedirection t =
|
||||||
|
|
||||||
isFunction t = case t of T_Function {} -> True; _ -> False
|
isFunction t = case t of T_Function {} -> True; _ -> False
|
||||||
|
|
||||||
-- Get the list of commands from tokens that contain them, such as
|
-- Get the lists of commands from tokens that contain them, such as
|
||||||
-- the body of while loops and if statements.
|
-- the body of while loops or branches of if statements.
|
||||||
getCommandSequences t =
|
getCommandSequences t =
|
||||||
case t of
|
case t of
|
||||||
T_Script _ _ cmds -> [cmds]
|
T_Script _ _ cmds -> [cmds]
|
||||||
|
@ -252,6 +265,7 @@ getCommandSequences t =
|
||||||
T_IfExpression _ thens elses -> map snd thens ++ [elses]
|
T_IfExpression _ thens elses -> map snd thens ++ [elses]
|
||||||
otherwise -> []
|
otherwise -> []
|
||||||
|
|
||||||
|
-- Get a list of names of associative arrays
|
||||||
getAssociativeArrays t =
|
getAssociativeArrays t =
|
||||||
nub . execWriter $ doAnalysis f t
|
nub . execWriter $ doAnalysis f t
|
||||||
where
|
where
|
||||||
|
|
|
@ -765,6 +765,7 @@ prop_checkUnquotedExpansions4 = verifyNot checkUnquotedExpansions "[[ $(foo) ==
|
||||||
prop_checkUnquotedExpansions5 = verifyNot checkUnquotedExpansions "for f in $(cmd); do echo $f; done"
|
prop_checkUnquotedExpansions5 = verifyNot checkUnquotedExpansions "for f in $(cmd); do echo $f; done"
|
||||||
prop_checkUnquotedExpansions6 = verifyNot checkUnquotedExpansions "$(cmd)"
|
prop_checkUnquotedExpansions6 = verifyNot checkUnquotedExpansions "$(cmd)"
|
||||||
prop_checkUnquotedExpansions7 = verifyNot checkUnquotedExpansions "cat << foo\n$(ls)\nfoo"
|
prop_checkUnquotedExpansions7 = verifyNot checkUnquotedExpansions "cat << foo\n$(ls)\nfoo"
|
||||||
|
prop_checkUnquotedExpansions8 = verifyNot checkUnquotedExpansions "set -- $(seq 1 4)"
|
||||||
checkUnquotedExpansions params =
|
checkUnquotedExpansions params =
|
||||||
check
|
check
|
||||||
where
|
where
|
||||||
|
@ -774,9 +775,12 @@ checkUnquotedExpansions params =
|
||||||
check _ = return ()
|
check _ = return ()
|
||||||
tree = parentMap params
|
tree = parentMap params
|
||||||
examine t =
|
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."
|
warn (getId t) 2046 "Quote this to prevent word splitting."
|
||||||
|
|
||||||
|
shouldBeSplit t =
|
||||||
|
getCommandNameFromExpansion t == Just "seq"
|
||||||
|
|
||||||
|
|
||||||
prop_checkRedirectToSame = verify checkRedirectToSame "cat foo > foo"
|
prop_checkRedirectToSame = verify checkRedirectToSame "cat foo > foo"
|
||||||
prop_checkRedirectToSame2 = verify checkRedirectToSame "cat lol | sed -e 's/a/b/g' > lol"
|
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"
|
,"alias"
|
||||||
,"sudo" -- covering "sudo sh" and such
|
,"sudo" -- covering "sudo sh" and such
|
||||||
,"dpkg-query"
|
,"dpkg-query"
|
||||||
|
,"jq" -- could also check that user provides --arg
|
||||||
]
|
]
|
||||||
|| "awk" `isSuffixOf` commandName
|
|| "awk" `isSuffixOf` commandName
|
||||||
|| "perl" `isPrefixOf` commandName
|
|| "perl" `isPrefixOf` commandName
|
||||||
|
|
Loading…
Reference in New Issue