Treat 'exec $1' like '$1' for the purpose of quoting (fixes #2068)

This commit is contained in:
Vidar Holen 2020-12-17 20:30:39 -08:00
parent cc3884cf9f
commit bd3299edd3
3 changed files with 5 additions and 2 deletions

View File

@ -422,6 +422,7 @@ getCommandNameAndToken direct t = fromMaybe (Nothing, t) $ do
"busybox" -> firstArg "busybox" -> firstArg
"builtin" -> firstArg "builtin" -> firstArg
"command" -> firstArg "command" -> firstArg
"run" -> firstArg -- Used by bats
"exec" -> do "exec" -> do
opts <- getBsdOpts "cla:" args opts <- getBsdOpts "cla:" args
(_, (t, _)) <- listToMaybe $ filter (null . fst) opts (_, (t, _)) <- listToMaybe $ filter (null . fst) opts

View File

@ -1853,6 +1853,8 @@ prop_checkSpacefulness37v = verifyTree checkVerboseSpacefulness "@test 'status'
prop_checkSpacefulness38= verifyTree checkSpacefulness "a=; echo $a" prop_checkSpacefulness38= verifyTree checkSpacefulness "a=; echo $a"
prop_checkSpacefulness39= verifyNotTree checkSpacefulness "a=''\"\"''; b=x$a; echo $b" prop_checkSpacefulness39= verifyNotTree checkSpacefulness "a=''\"\"''; b=x$a; echo $b"
prop_checkSpacefulness40= verifyNotTree checkSpacefulness "a=$((x+1)); echo $a" 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) data SpaceStatus = SpaceSome | SpaceNone | SpaceEmpty deriving (Eq)
instance Semigroup SpaceStatus where instance Semigroup SpaceStatus where

View File

@ -370,8 +370,8 @@ usedAsCommandName tree token = go (getId token) (tail $ getPath tree token)
| currentId == getId word = go id rest | currentId == getId word = go id rest
go currentId (T_DoubleQuoted id [word]:rest) go currentId (T_DoubleQuoted id [word]:rest)
| currentId == getId word = go id rest | currentId == getId word = go id rest
go currentId (T_SimpleCommand _ _ (word:_):_) go currentId (t@(T_SimpleCommand _ _ (word:_)):_) =
| currentId == getId word = True getId word == currentId || getId (getCommandTokenOrThis t) == currentId
go _ _ = False go _ _ = False
-- A list of the element and all its parents up to the root node. -- A list of the element and all its parents up to the root node.