From c53c8a5eaddecf78937850d41d5b467ff5ab2358 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 17 Mar 2019 19:37:35 -0700 Subject: [PATCH] Allow using 'source -- file' (fixes #1518) --- src/ShellCheck/Checker.hs | 3 +++ src/ShellCheck/Parser.hs | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ShellCheck/Checker.hs b/src/ShellCheck/Checker.hs index 8b3eb76..471c364 100644 --- a/src/ShellCheck/Checker.hs +++ b/src/ShellCheck/Checker.hs @@ -204,6 +204,9 @@ prop_failsWhenNotSourcing = prop_worksWhenSourcing = null $ checkWithIncludes [("lib", "bar=1")] "source lib; echo \"$bar\"" +prop_worksWhenSourcingWithDashDash = + null $ checkWithIncludes [("lib", "bar=1")] "source -- lib; echo \"$bar\"" + prop_worksWhenDotting = null $ checkWithIncludes [("lib", "bar=1")] ". lib; echo \"$bar\"" diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 0289e0d..4ecf602 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -2062,7 +2062,8 @@ readSimpleCommand = called "simple command" $ do readSource :: Monad m => Token -> SCParser m Token -readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file:_))) = do +readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = do + let file = getFile file' rest' override <- getSourceOverride let literalFile = do name <- override `mplus` getLiteralString file @@ -2107,6 +2108,13 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file:_))) = do included <|> failed where + getFile :: Token -> [Token] -> Token + getFile file (next:rest) = + case getLiteralString file of + Just "--" -> next + x -> file + getFile file _ = file + subRead name script = withContext (ContextSource name) $ inSeparateContext $