From 3f296a08c19d518ee824915e2b13b6bda3fc703a Mon Sep 17 00:00:00 2001 From: Gandalf- Date: Wed, 18 Dec 2019 20:23:48 -0800 Subject: [PATCH] Issue 1731 Literals in case patterns https://github.com/koalaman/shellcheck/issues/1731 Any literal except esac is valid pattern in a case statement --- src/ShellCheck/Parser.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 849fbd7..42ec9c1 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -1040,14 +1040,16 @@ prop_readNormalWord9 = isOk readSubshell "(foo\\ ;\nbar)" prop_readNormalWord10 = isWarning readNormalWord "\x201Chello\x201D" prop_readNormalWord11 = isWarning readNormalWord "\x2018hello\x2019" prop_readNormalWord12 = isWarning readNormalWord "hello\x2018" -readNormalWord = readNormalishWord "" +readNormalWord = readNormalishWord "" ["do", "done", "then", "fi", "esac"] -readNormalishWord end = do +readPatternWord = readNormalishWord "" ["esac"] + +readNormalishWord end terms = do start <- startSpan pos <- getPosition x <- many1 (readNormalWordPart end) id <- endSpan start - checkPossibleTermination pos x + checkPossibleTermination pos x terms return $ T_NormalWord id x readIndexSpan = do @@ -1067,10 +1069,10 @@ readIndexSpan = do id <- endSpan start return $ T_Literal id str -checkPossibleTermination pos [T_Literal _ x] = - when (x `elem` ["do", "done", "then", "fi", "esac"]) $ +checkPossibleTermination pos [T_Literal _ x] terminators = + when (x `elem` terminators) $ parseProblemAt pos WarningC 1010 $ "Use semicolon or linefeed before '" ++ x ++ "' (or quote to make it literal)." -checkPossibleTermination _ _ = return () +checkPossibleTermination _ _ _ = return () readNormalWordPart end = do notFollowedBy2 $ oneOf end @@ -2655,7 +2657,7 @@ readCoProc = called "coproc" $ do return $ T_CoProcBody id body -readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing) +readPattern = (readPatternWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing) prop_readCompoundCommand = isOk readCompoundCommand "{ echo foo; }>/dev/null" readCompoundCommand = do