From cbda90eeb51c3a213a590a3aea0ef9a45d8b298c Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 25 Jul 2015 13:59:00 -0700 Subject: [PATCH] Warn about zero-width spaces. --- ShellCheck/Parser.hs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index e826e37..ed38474 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -46,14 +46,14 @@ variableStart = upper <|> lower <|> oneOf "_" variableChars = upper <|> lower <|> digit <|> oneOf "_" functionChars = variableChars <|> oneOf ":+-.?" specialVariable = oneOf "@*#?-$!" -tokenDelimiter = oneOf "&|;<> \t\n\r" <|> nbsp +tokenDelimiter = oneOf "&|;<> \t\n\r" <|> almostSpace quotableChars = "|&;<>()\\ '\t\n\r\xA0" ++ doubleQuotableChars -quotable = nbsp <|> unicodeDoubleQuote <|> oneOf quotableChars +quotable = almostSpace <|> unicodeDoubleQuote <|> oneOf quotableChars bracedQuotable = oneOf "}\"$`'" doubleQuotableChars = "\"$`" ++ unicodeDoubleQuoteChars doubleQuotable = unicodeDoubleQuote <|> oneOf doubleQuotableChars -whitespace = oneOf " \t\n" <|> carriageReturn <|> nbsp -linewhitespace = oneOf " \t" <|> nbsp +whitespace = oneOf " \t\n" <|> carriageReturn <|> almostSpace +linewhitespace = oneOf " \t" <|> almostSpace suspectCharAfterQuotes = variableChars <|> char '%' @@ -105,10 +105,16 @@ carriageReturn = do parseNote ErrorC 1017 "Literal carriage return. Run script through tr -d '\\r' ." char '\r' -nbsp = do - parseNote ErrorC 1018 "This is a  . Delete it and retype as space." - char '\xA0' - return ' ' +almostSpace = + choice [ + check '\xA0' "unicode non-breaking space", + check '\x200B' "unicode zerowidth space" + ] + where + check c name = do + parseNote ErrorC 1018 $ "This is a " ++ name ++ ". Delete and retype it." + char c + return ' ' --------- Message/position annotation on top of user state data Note = Note Id Severity Code String deriving (Show, Eq)