From 56751413b446ebfc6e5fc8c5170ec2753397fbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=CC=88hl?= Date: Wed, 24 Jan 2018 13:04:26 +0100 Subject: [PATCH 1/2] SC2029: Add false positive test This change adds a test case for a valid command that gets falsely flagged with SC2029. --- ShellCheck/Checks/Commands.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/ShellCheck/Checks/Commands.hs b/ShellCheck/Checks/Commands.hs index f7ce2dd..2905c93 100644 --- a/ShellCheck/Checks/Commands.hs +++ b/ShellCheck/Checks/Commands.hs @@ -482,6 +482,7 @@ checkInteractiveSu = CommandCheck (Basename "su") f prop_checkSshCmdStr1 = verify checkSshCommandString "ssh host \"echo $PS1\"" prop_checkSshCmdStr2 = verifyNot checkSshCommandString "ssh host \"ls foo\"" prop_checkSshCmdStr3 = verifyNot checkSshCommandString "ssh \"$host\"" +prop_checkSshCmdStr4 = verifyNot checkSshCommandString "ssh -i key \"$host\"" checkSshCommandString = CommandCheck (Basename "ssh") (f . arguments) where nonOptions = From ccaacb108a64705aac29cf5f0e91901964d713d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=CC=88hl?= Date: Wed, 24 Jan 2018 13:05:22 +0100 Subject: [PATCH 2/2] SC2029: Skip when there are options to ssh Fixes #327 SC2029 generates false positives when given an ssh command that includes options with arguments because it assumes the first non-option must be the host:port argument and the last argument is a command to run. As suggested the comments on #327, this change fixes those by skipping the check when there are any options present. --- ShellCheck/Checks/Commands.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ShellCheck/Checks/Commands.hs b/ShellCheck/Checks/Commands.hs index 2905c93..b7b625c 100644 --- a/ShellCheck/Checks/Commands.hs +++ b/ShellCheck/Checks/Commands.hs @@ -485,11 +485,10 @@ prop_checkSshCmdStr3 = verifyNot checkSshCommandString "ssh \"$host\"" prop_checkSshCmdStr4 = verifyNot checkSshCommandString "ssh -i key \"$host\"" checkSshCommandString = CommandCheck (Basename "ssh") (f . arguments) where - nonOptions = - filter (\x -> not $ "-" `isPrefixOf` concat (oversimplify x)) + isOption x = "-" `isPrefixOf` (concat $ oversimplify x) f args = - case nonOptions args of - (hostport:r@(_:_)) -> checkArg $ last r + case partition isOption args of + ([], hostport:r@(_:_)) -> checkArg $ last r _ -> return () checkArg (T_NormalWord _ [T_DoubleQuoted id parts]) = case filter (not . isConstant) parts of