Merge pull request #1735 from gabrielelana/quoted-heredoc

Support for heredoc quoted token like `'"FOO"`
This commit is contained in:
Vidar Holen 2019-11-15 20:27:10 -08:00 committed by GitHub
commit 2bbfd0570d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -1741,6 +1741,7 @@ prop_readHereDoc14= isWarning readScript "cat << foo\nbar\nfoo \n"
prop_readHereDoc15= isWarning readScript "cat <<foo\nbar\nfoo bar\nfoo"
prop_readHereDoc16= isOk readScript "cat <<- ' foo'\nbar\n foo\n"
prop_readHereDoc17= isWarning readScript "cat <<- ' foo'\nbar\n foo\n foo\n"
prop_readHereDoc18= isOk readScript "cat <<'\"foo'\nbar\n\"foo\n"
prop_readHereDoc20= isWarning readScript "cat << foo\n foo\n()\nfoo\n"
prop_readHereDoc21= isOk readScript "# shellcheck disable=SC1039\ncat << foo\n foo\n()\nfoo\n"
readHereDoc = called "here document" $ do
@ -1761,14 +1762,17 @@ readHereDoc = called "here document" $ do
addPendingHereDoc doc
return doc
where
quotes = "\"'\\"
unquote :: String -> (Quoted, String)
unquote "" = (Unquoted, "")
unquote [c] = (Unquoted, [c])
unquote s@(cl:tl) =
case reverse tl of
(cr:tr) | cr == cl && cl `elem` "\"'" -> (Quoted, reverse tr)
_ -> (if '\\' `elem` s then (Quoted, filter ((/=) '\\') s) else (Unquoted, s))
-- Fun fact: bash considers << foo"" quoted, but not << <("foo").
-- Instead of replicating this, just read a token and strip quotes.
readToken = do
str <- readStringForParser readNormalWord
return (if any (`elem` quotes) str then Quoted else Unquoted,
filter (not . (`elem` quotes)) str)
return $ unquote str
readPendingHereDocs = do
docs <- popPendingHereDocs