Added check for [[ foo == $bar ]]

This commit is contained in:
Vidar Holen 2012-11-15 23:43:57 -08:00
parent a2cc44a04d
commit 686c895858
1 changed files with 8 additions and 0 deletions

View File

@ -38,6 +38,7 @@ basicChecks = [
,checkForDecimals
,checkDivBeforeMult
,checkArithmeticDeref
,checkComparisonAgainstGlob
]
modifyMap = modify
@ -260,6 +261,13 @@ checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem
addNoteFor id $ Note WarningC $ "Don't use $ on variables in (( )) unless you want to dereference twice"
checkArithmeticDeref _ = return ()
prop_checkComparisonAgainstGlob = verify checkComparisonAgainstGlob "[[ $cow == $bar ]]"
prop_checkComparisonAgainstGlob2 = verifyNot checkComparisonAgainstGlob "[[ $cow == \"$bar\" ]]"
checkComparisonAgainstGlob (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _])) | op == "=" || op == "==" =
addNoteFor id $ Note WarningC $ "Quote the rhs of = in [[ ]] to prevent glob interpretation"
checkComparisonAgainstGlob _ = return ()
allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables x)) t) []
--- Subshell detection