mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-07 20:23:03 +08:00
Made unquoted $(..) check more robust
This commit is contained in:
@@ -32,6 +32,7 @@ checks = concat [
|
|||||||
map runBasicAnalysis basicChecks
|
map runBasicAnalysis basicChecks
|
||||||
,[subshellAssignmentCheck]
|
,[subshellAssignmentCheck]
|
||||||
,[checkSpacefulness]
|
,[checkSpacefulness]
|
||||||
|
,[checkUnquotedExpansions]
|
||||||
]
|
]
|
||||||
|
|
||||||
runAllAnalytics = checkList checks
|
runAllAnalytics = checkList checks
|
||||||
@@ -43,7 +44,6 @@ basicChecks = [
|
|||||||
,checkPipePitfalls
|
,checkPipePitfalls
|
||||||
,checkForInQuoted
|
,checkForInQuoted
|
||||||
,checkForInLs
|
,checkForInLs
|
||||||
,checkUnquotedExpansions
|
|
||||||
,checkRedirectToSame
|
,checkRedirectToSame
|
||||||
,checkShorthandIf
|
,checkShorthandIf
|
||||||
,checkDollarStar
|
,checkDollarStar
|
||||||
@@ -81,7 +81,6 @@ willSplit x =
|
|||||||
T_Literal _ s -> isGlob s
|
T_Literal _ s -> isGlob s
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
|
|
||||||
isGlob str = any (`elem` str) "*?"
|
isGlob str = any (`elem` str) "*?"
|
||||||
|
|
||||||
makeSimple (T_NormalWord _ [f]) = f
|
makeSimple (T_NormalWord _ [f]) = f
|
||||||
@@ -189,11 +188,21 @@ checkForInLs (T_ForIn _ f [T_NormalWord _ [T_DollarExpansion id [x]]] _) =
|
|||||||
checkForInLs _ = return ()
|
checkForInLs _ = return ()
|
||||||
|
|
||||||
|
|
||||||
prop_checkUnquotedExpansions = verify checkUnquotedExpansions "rm $(ls)"
|
prop_checkUnquotedExpansions1 = verifyFull checkUnquotedExpansions "rm $(ls)"
|
||||||
checkUnquotedExpansions (T_SimpleCommand _ _ cmds) = mapM_ check cmds
|
prop_checkUnquotedExpansions2 = verifyFull checkUnquotedExpansions "rm foo$(date)"
|
||||||
where check (T_NormalWord _ [T_DollarExpansion id _]) = warn id "Quote the expansion to prevent word splitting."
|
prop_checkUnquotedExpansions3 = verifyFull checkUnquotedExpansions "[ $(foo) == cow ]"
|
||||||
check _ = return ()
|
prop_checkUnquotedExpansions4 = verifyNotFull checkUnquotedExpansions "[[ $(foo) == cow ]]"
|
||||||
checkUnquotedExpansions _ = return ()
|
prop_checkUnquotedExpansions5 = verifyNotFull checkUnquotedExpansions "for f in $(cmd); do echo $f; done"
|
||||||
|
checkUnquotedExpansions t metaMap =
|
||||||
|
runBasicAnalysis check t metaMap
|
||||||
|
where
|
||||||
|
tree = getParentTree t
|
||||||
|
msg id = warn id "Quote this to prevent word splitting."
|
||||||
|
check (T_NormalWord _ l) = mapM_ check' l
|
||||||
|
check _ = return ()
|
||||||
|
|
||||||
|
check' t@(T_DollarExpansion id _) = unless (inUnquotableContext tree t) $ msg id
|
||||||
|
check' _ = return ()
|
||||||
|
|
||||||
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"
|
||||||
|
Reference in New Issue
Block a user