Don't warn when $(seq) is used unquoted.

This commit is contained in:
Vidar Holen
2016-07-01 21:26:46 -07:00
parent e3bef9dc97
commit 50084c06c5
2 changed files with 22 additions and 3 deletions

View File

@@ -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