From 22710bf4d8b60d6dd9cc95a1372ba5b2794f8e75 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 22 Nov 2014 11:21:54 -0800 Subject: [PATCH] Fixed $! counting as a positional parameter reference. --- ShellCheck/Analytics.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 825c919..cbe4ef0 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -2066,7 +2066,17 @@ getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal getModifiedVariableCommand _ = [] -- TODO: -getBracedReference s = takeWhile (`notElem` ":[#%/^,") $ dropWhile (`elem` "#!") s +getBracedReference s = + case filter (not . null) [ + dropSuffix $ dropPrefix s, + dropSuffix s, + s] of + (a:_) -> a + [] -> error "Internal ShellCheck error (empty braced reference). Please file a bug!" + where + dropSuffix = takeWhile (`notElem` ":[#%/^,") + dropPrefix = dropWhile (`elem` "#!") + getIndexReferences s = fromMaybe [] $ do (_, index, _, _) <- matchRegexAll re s return $ matchAll variableNameRegex index @@ -2730,6 +2740,7 @@ prop_checkUnpassedInFunctions6 = verifyNotTree checkUnpassedInFunctions "foo() { prop_checkUnpassedInFunctions7 = verifyTree checkUnpassedInFunctions "foo() { echo $1; }; foo; foo;" prop_checkUnpassedInFunctions8 = verifyNotTree checkUnpassedInFunctions "foo() { echo $((1)); }; foo;" prop_checkUnpassedInFunctions9 = verifyNotTree checkUnpassedInFunctions "foo() { echo $(($b)); }; foo;" +prop_checkUnpassedInFunctions10= verifyNotTree checkUnpassedInFunctions "foo() { echo $!; }; foo;" checkUnpassedInFunctions params root = execWriter $ mapM_ warnForGroup referenceGroups where