From 5de7a39f3eb4809c92b0cc047fadb04510e64f3c Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 5 Nov 2012 01:32:36 -0800 Subject: [PATCH] Added error for 2>&1 > lol --- Shpell/Analytics.hs | 17 +++++++++++++++-- badcase/twogreaterandone | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 badcase/twogreaterandone diff --git a/Shpell/Analytics.hs b/Shpell/Analytics.hs index dac65f1..1f01356 100644 --- a/Shpell/Analytics.hs +++ b/Shpell/Analytics.hs @@ -22,7 +22,8 @@ basicChecks = [ checkRedirectToSame, checkShorthandIf, checkForInDollarStar, - checkUnquotedDollarAt + checkUnquotedDollarAt, + checkStderrRedirect ] modifyMap = modify @@ -81,7 +82,7 @@ isMagicInQuotes _ = False prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done" prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done" checkForInQuoted (T_ForIn _ f [T_NormalWord _ [T_DoubleQuoted id list]] _) = - when (any (\x -> willSplit x && not (isMagicInQuotes x)) list) $ + when (any (\x -> willSplit x && not (isMagicInQuotes x)) list) $ addNoteFor id $ Note ErrorC $ "Since you double quoted this, it will not word split, and the loop will only run once" checkForInQuoted _ = return () @@ -155,4 +156,16 @@ checkUnquotedDollarAt (T_NormalWord _ [T_DollarVariable id "@"]) = addNoteFor id $ Note ErrorC $ "Add double quotes around $@, otherwise it's just like $* and breaks on spaces" checkUnquotedDollarAt _ = return () +prop_checkStderrRedirect = verify checkStderrRedirect "test 2>&1 > cow" +prop_checkStderrRedirect2 = verifyNot checkStderrRedirect "test > cow 2>&1" +checkStderrRedirect (T_Redirecting _ [ + T_FdRedirect id "2" (T_IoFile _ (T_GREATAND _) (T_NormalWord _ [T_Literal _ "1"])), + T_FdRedirect _ _ (T_IoFile _ op _) + ] _) = case op of + T_Greater _ -> error + T_DGREAT _ -> error + _ -> return () + where error = addNoteFor id $ Note ErrorC $ "The order of the 2>&1 and the redirect matters. The 2>&1 has to be last." +checkStderrRedirect _ = return () + lt x = trace (show x) x diff --git a/badcase/twogreaterandone b/badcase/twogreaterandone new file mode 100644 index 0000000..1438d22 --- /dev/null +++ b/badcase/twogreaterandone @@ -0,0 +1 @@ +strace foo 2>&1 > allmessages