From 699aac589acb38445a76c95ba1602211cb6204a5 Mon Sep 17 00:00:00 2001 From: "gabriele.lana" Date: Sat, 26 Oct 2019 17:36:32 +0200 Subject: [PATCH] Support for heredoc quoted token like `'"FOO"` Fixes #1650 --- src/ShellCheck/Parser.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 075d486..d4dabe6 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -1739,6 +1739,7 @@ prop_readHereDoc14= isWarning readScript "cat << foo\nbar\nfoo \n" prop_readHereDoc15= isWarning readScript "cat < (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