diff --git a/CHANGELOG.md b/CHANGELOG.md index 596db82..ff36bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ is still purely cosmetic and does not allow ShellCheck to continue. - Improved error reporting for trailing tokens after ]/]] and compound commands - `#!/usr/bin/env -S shell` is now handled correctly +- Here docs with \r are now parsed correctly and give better warnings ### Changed - Assignments are now parsed to spec, without leniency for leading $ or spaces diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index b70e4f4..afe6262 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -123,8 +123,10 @@ readUnicodeQuote = do return $ T_Literal id [c] carriageReturn = do - parseNote ErrorC 1017 "Literal carriage return. Run script through tr -d '\\r' ." + pos <- getPosition char '\r' + parseProblemAt pos ErrorC 1017 "Literal carriage return. Run script through tr -d '\\r' ." + return '\r' almostSpace = choice [ @@ -1761,6 +1763,8 @@ 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" +prop_readHereDoc22 = isWarning readScript "cat << foo\r\ncow\r\nfoo\r\n" +prop_readHereDoc23 = isNotOk readScript "cat << foo \r\ncow\r\nfoo\r\n" readHereDoc = called "here document" $ do pos <- getPosition try $ string "<<" @@ -1789,7 +1793,9 @@ readHereDoc = called "here document" $ do -- Fun fact: bash considers << foo"" quoted, but not << <("foo"). readToken = do str <- readStringForParser readNormalWord - return $ unquote str + -- A here doc actually works with \r\n because the \r becomes part of the token + crstr <- (carriageReturn >> (return $ str ++ "\r")) <|> return str + return $ unquote crstr readPendingHereDocs = do docs <- popPendingHereDocs