From c566efd44241a39eca9d9e9094776036ddd78ae3 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 3 May 2014 10:37:12 -0700 Subject: [PATCH] Warn about UTF-8 BOMs in scripts. --- ShellCheck/Parser.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index d933e67..19c231b 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1271,8 +1271,8 @@ readHereString = called "here string" $ do readNewlineList = many1 ((newline <|> carriageReturn) `thenSkip` spacing) readLineBreak = optional readNewlineList -prop_roflol = isWarning readScript "a &; b" -prop_roflol2 = isOk readScript "a & b" +prop_readSeparator1 = isWarning readScript "a &; b" +prop_readSeparator2 = isOk readScript "a & b" readSeparatorOp = do notFollowedBy2 (g_AND_IF <|> g_DSEMI) notFollowedBy2 (string "&>") @@ -1917,6 +1917,10 @@ prop_readScript4 = isWarning readScript "#!/usr/bin/perl\nfoo=(" readScript = do id <- getNextId pos <- getPosition + optional $ do + readUtf8Bom + parseProblem ErrorC 1082 $ + "This file has a UTF-8 BOM. Remove it with: LC_CTYPE=C sed '1s/^...//' < yourscript ." sb <- option "" readShebang verifyShell pos (getShell sb) if (isValidShell $ getShell sb) /= Just False @@ -1976,6 +1980,8 @@ readScript = do "tcsh" ] + readUtf8Bom = called "Byte Order Mark" $ string "\xFEFF" + rp p filename contents = Ms.runState (runParserT p initialState filename contents) ([], []) isWarning p s = (fst cs) && (not . null . snd $ cs) where cs = checkString p s