From 03ce3b15b69ae3cb70766a00d275e881c1a4d823 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Wed, 18 Jul 2018 22:31:58 -0700 Subject: [PATCH] Fix false positive when indexing into array in cond Fixes #1268 --- src/ShellCheck/Parser.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 70ad72f..3609353 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -520,7 +520,7 @@ readConditionContents single = notFollowedBy2 (try (spacing >> string "]")) x <- readNormalWord pos <- getPosition - when (endedWith "]" x) $ do + when (endedWith "]" x && notArrayIndex x) $ do parseProblemAt pos ErrorC 1020 $ "You need a space before the " ++ (if single then "]" else "]]") ++ "." fail "Missing space before ]" @@ -534,6 +534,8 @@ readConditionContents single = case last s of T_Literal id s -> str `isSuffixOf` s _ -> False endedWith _ _ = False + notArrayIndex (T_NormalWord id s@(_:T_Literal _ t:_)) = t /= "[" + notArrayIndex _ = True readCondAndOp = readAndOrOp TC_And "&&" False <|> readAndOrOp TC_And "-a" True