From 60f75e5b8a5460812c6bb89099ad562229ca0e17 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 13 Oct 2019 20:26:40 -0700 Subject: [PATCH] Warn about unexpected characters after ]/]] (fixes #1680) --- src/ShellCheck/Parser.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index b2935fd..075d486 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -910,6 +910,7 @@ prop_readCondition20 = isOk readCondition "[[ echo_rc -eq 0 ]]" prop_readCondition21 = isOk readCondition "[[ $1 =~ ^(a\\ b)$ ]]" prop_readCondition22 = isOk readCondition "[[ $1 =~ \\.a\\.(\\.b\\.)\\.c\\. ]]" prop_readCondition23 = isOk readCondition "[[ -v arr[$var] ]]" +prop_readCondition24 = isWarning readCondition "[[ 1 == 2 ]]]" readCondition = called "test expression" $ do opos <- getPosition start <- startSpan @@ -938,6 +939,11 @@ readCondition = called "test expression" $ do id <- endSpan start when (open == "[[" && close /= "]]") $ parseProblemAt cpos ErrorC 1033 "Did you mean ]] ?" when (open == "[" && close /= "]" ) $ parseProblemAt opos ErrorC 1034 "Did you mean [[ ?" + optional $ lookAhead $ do + pos <- getPosition + notFollowedBy2 readCmdWord <|> + parseProblemAt pos ErrorC 1136 + ("Unexpected characters after terminating " ++ close ++ ". Missing semicolon/linefeed?") spacing many readCmdWord -- Read and throw away remainders to get then/do warnings. Fixme? return $ T_Condition id typ condition