From 0347ce1b7ad4544205a9aa0ddba34cb6ab97506b Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 26 Jul 2014 13:14:28 -0700 Subject: [PATCH] Warn about quoted ~ in PATH --- ShellCheck/Analytics.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 6943f09..de7bb4b 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -207,6 +207,7 @@ nodeChecks = [ ,checkTestGlobs ,checkConcatenatedDollarAt ,checkFindActionPrecedence + ,checkTildeInPath ] @@ -2712,6 +2713,22 @@ checkOverridingPath _ (T_SimpleCommand _ vars []) = notify id = warn id 2123 "PATH is the shell search path. Use another name." checkOverridingPath _ _ = return () +prop_checkTildeInPath1 = verify checkTildeInPath "PATH=\"$PATH:~/bin\"" +prop_checkTildeInPath2 = verify checkTildeInPath "PATH='~foo/bin'" +prop_checkTildeInPath3 = verifyNot checkTildeInPath "PATH=~/bin" +checkTildeInPath _ (T_SimpleCommand _ vars _) = + mapM_ checkVar vars + where + checkVar (T_Assignment id Assign "PATH" Nothing (T_NormalWord _ parts)) = + when (any (\x -> isQuoted x && hasTilde x) parts) $ + warn id 2147 "Literal tilde in PATH works poorly across programs." + checkVar _ = return () + + hasTilde t = fromMaybe False (liftM2 elem (return '~') (getLiteralStringExt (const $ return "") t)) + isQuoted (T_DoubleQuoted {}) = True + isQuoted (T_SingleQuoted {}) = True + isQuoted _ = False +checkTildeInPath _ _ = return () prop_checkUnsupported1 = verifyNot checkUnsupported "#!/bin/zsh\nfunction { echo cow; }" prop_checkUnsupported2 = verify checkUnsupported "#!/bin/sh\nfunction { echo cow; }"