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