Warn for possible bad quote nesting like 'echo 'foo''

This commit is contained in:
Vidar Holen 2013-07-01 10:01:58 -07:00
parent 651bab73de
commit 499f7c8733
1 changed files with 12 additions and 0 deletions

View File

@ -120,6 +120,7 @@ basicChecks = [
,checkSudoRedirect
,checkPS1Assignments
,checkBackticks
,checkInexplicablyUnquoted
]
treeChecks = [
checkUnquotedExpansions
@ -1075,6 +1076,17 @@ checkIndirectExpansion (T_DollarBraced id (T_NormalWord _ ((T_Literal _ s):attem
else return ()
checkIndirectExpansion _ = return ()
prop_checkInexplicablyUnquoted1 = verify checkInexplicablyUnquoted "echo 'var='value';'"
prop_checkInexplicablyUnquoted2 = verifyNot checkInexplicablyUnquoted "'foo'*"
prop_checkInexplicablyUnquoted3 = verifyNot checkInexplicablyUnquoted "wget --user-agent='something'"
checkInexplicablyUnquoted (T_NormalWord id tokens) = mapM_ check (tails tokens)
where
check ((T_SingleQuoted _ _):(T_Literal id str):_)
| all isAlphaNum str =
info id $ "This word is outside of quotes. Did you intend to 'nest '\"'single quotes'\"' instead'? "
check _ = return ()
checkInexplicablyUnquoted _ = return ()
--- Subshell detection
prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""