From bd3299edd3b517f92f74c2e3327c9f6b72b31f7c Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 17 Dec 2020 20:30:39 -0800 Subject: [PATCH] Treat 'exec $1' like '$1' for the purpose of quoting (fixes #2068) --- src/ShellCheck/ASTLib.hs | 1 + src/ShellCheck/Analytics.hs | 2 ++ src/ShellCheck/AnalyzerLib.hs | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/ASTLib.hs b/src/ShellCheck/ASTLib.hs index a09bf38..dcc9904 100644 --- a/src/ShellCheck/ASTLib.hs +++ b/src/ShellCheck/ASTLib.hs @@ -422,6 +422,7 @@ getCommandNameAndToken direct t = fromMaybe (Nothing, t) $ do "busybox" -> firstArg "builtin" -> firstArg "command" -> firstArg + "run" -> firstArg -- Used by bats "exec" -> do opts <- getBsdOpts "cla:" args (_, (t, _)) <- listToMaybe $ filter (null . fst) opts diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index 2e1adca..2fb1253 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -1853,6 +1853,8 @@ prop_checkSpacefulness37v = verifyTree checkVerboseSpacefulness "@test 'status' prop_checkSpacefulness38= verifyTree checkSpacefulness "a=; echo $a" prop_checkSpacefulness39= verifyNotTree checkSpacefulness "a=''\"\"''; b=x$a; echo $b" prop_checkSpacefulness40= verifyNotTree checkSpacefulness "a=$((x+1)); echo $a" +prop_checkSpacefulness41= verifyNotTree checkSpacefulness "exec $1 --flags" +prop_checkSpacefulness42= verifyNotTree checkSpacefulness "run $1 --flags" data SpaceStatus = SpaceSome | SpaceNone | SpaceEmpty deriving (Eq) instance Semigroup SpaceStatus where diff --git a/src/ShellCheck/AnalyzerLib.hs b/src/ShellCheck/AnalyzerLib.hs index 38e9c1d..194bf18 100644 --- a/src/ShellCheck/AnalyzerLib.hs +++ b/src/ShellCheck/AnalyzerLib.hs @@ -370,8 +370,8 @@ usedAsCommandName tree token = go (getId token) (tail $ getPath tree token) | currentId == getId word = go id rest go currentId (T_DoubleQuoted id [word]:rest) | currentId == getId word = go id rest - go currentId (T_SimpleCommand _ _ (word:_):_) - | currentId == getId word = True + go currentId (t@(T_SimpleCommand _ _ (word:_)):_) = + getId word == currentId || getId (getCommandTokenOrThis t) == currentId go _ _ = False -- A list of the element and all its parents up to the root node.