提交 a20a3499 编写于 作者: V Vidar Holen

Improved bad indirection detection

上级 73c62028
...@@ -1096,16 +1096,26 @@ checkBackticks _ = return () ...@@ -1096,16 +1096,26 @@ checkBackticks _ = return ()
prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}" prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}"
prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}" prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}"
checkIndirectExpansion (T_DollarBraced id (T_NormalWord _ ((T_Literal _ s):attempt:_))) = prop_checkIndirectExpansion3 = verify checkIndirectExpansion "${$#}"
case attempt of T_DollarExpansion _ _ -> doit prop_checkIndirectExpansion4 = verify checkIndirectExpansion "${var${n}_$((i%2))}"
T_Backticked _ _ -> doit prop_checkIndirectExpansion5 = verifyNot checkIndirectExpansion "${bar}"
T_DollarBraced _ _ -> doit checkIndirectExpansion (T_DollarBraced i (T_NormalWord _ contents)) =
T_DollarArithmetic _ _ -> doit when (isIndirection contents) $
_ -> return () err i "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\"."
where where
doit = if all isVariableChar s isIndirection vars =
then err id "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\"" let list = catMaybes (map isIndirectionPart vars) in
else return () not (null list) && all id list
isIndirectionPart t =
case t of T_DollarExpansion _ _ -> Just True
T_Backticked _ _ -> Just True
T_DollarBraced _ _ -> Just True
T_DollarArithmetic _ _ -> Just True
T_Literal _ s -> if all isVariableChar s
then Nothing
else Just False
_ -> Just False
checkIndirectExpansion _ = return () checkIndirectExpansion _ = return ()
prop_checkInexplicablyUnquoted1 = verify checkInexplicablyUnquoted "echo 'var='value';'" prop_checkInexplicablyUnquoted1 = verify checkInexplicablyUnquoted "echo 'var='value';'"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册