diff options
author | Vidar Holen <vidar@vidarholen.net> | 2023-07-30 16:52:40 -0700 |
---|---|---|
committer | Vidar Holen <vidar@vidarholen.net> | 2023-07-30 16:52:40 -0700 |
commit | 9490b9488627a06e0a4af1c11644b7936b8a2422 (patch) | |
tree | ec661baa38f720bc0b31386ba17c5a839b016636 | |
parent | 372c0b667e7b6f36a5f1a42a9802eb0246ee3e95 (diff) |
Save and restore pending here docs when sourcing files (fixes #2803)
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/ShellCheck/Checker.hs | 9 | ||||
-rw-r--r-- | src/ShellCheck/Parser.hs | 10 |
3 files changed, 19 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f4426e..c6c9513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ ## Git ### Added -- SC2324: Warn when x+=1 appends instead of increments. +- SC2324: Warn when x+=1 appends instead of increments ### Fixed +- source statements with here docs now work correctly ### Changed diff --git a/src/ShellCheck/Checker.hs b/src/ShellCheck/Checker.hs index b56be68..c79f90f 100644 --- a/src/ShellCheck/Checker.hs +++ b/src/ShellCheck/Checker.hs @@ -508,5 +508,14 @@ prop_rcCanSuppressEarlyProblems2 = null result csScript = "!/bin/bash\necho 'hello world'" } +prop_sourceWithHereDocWorks = null result + where + result = checkWithIncludes [("bar", "true\n")] "source bar << eof\nlol\neof" + +prop_hereDocsAreParsedWithoutTrailingLinefeed = 1044 `elem` result + where + result = check "cat << eof" + + return [] runTests = $quickCheckAll diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 9d7df00..341a435 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -2283,8 +2283,13 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d subRead name script = withContext (ContextSource name) $ - inSeparateContext $ - subParse (initialPos name) (readScriptFile True) script + inSeparateContext $ do + oldState <- getState + setState $ oldState { pendingHereDocs = [] } + result <- subParse (initialPos name) (readScriptFile True) script + newState <- getState + setState $ newState { pendingHereDocs = pendingHereDocs oldState } + return result readSource t = return t @@ -3322,6 +3327,7 @@ readScriptFile sourced = do then do commands <- readCompoundListOrEmpty id <- endSpan start + readPendingHereDocs verifyEof let script = T_Annotation annotationId annotations $ T_Script id shebang commands |