From 499f7c8733a45231c2872efcd50c90bc8610abcd Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 1 Jul 2013 10:01:58 -0700 Subject: [PATCH] Warn for possible bad quote nesting like 'echo 'foo'' --- ShellCheck/Analytics.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 4d6f25e..813dc06 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -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\""