mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-21 13:53:11 +08:00
Warn when using unescaped parens in eval.
This commit is contained in:
@@ -1484,7 +1484,8 @@ readSimpleCommand = called "simple command" $ do
|
|||||||
suffix <- option [] $ getParser readCmdSuffix cmd [
|
suffix <- option [] $ getParser readCmdSuffix cmd [
|
||||||
(["declare", "export", "local", "readonly", "typeset"], readModifierSuffix),
|
(["declare", "export", "local", "readonly", "typeset"], readModifierSuffix),
|
||||||
(["time"], readTimeSuffix),
|
(["time"], readTimeSuffix),
|
||||||
(["let"], readLetSuffix)
|
(["let"], readLetSuffix),
|
||||||
|
(["eval"], readEvalSuffix)
|
||||||
]
|
]
|
||||||
|
|
||||||
let result = makeSimpleCommand id1 id2 prefix [cmd] suffix
|
let result = makeSimpleCommand id1 id2 prefix [cmd] suffix
|
||||||
@@ -2013,6 +2014,15 @@ readLetSuffix = many1 (readIoRedirect <|> try readLetExpression <|> readCmdWord)
|
|||||||
expression <- readStringForParser readCmdWord
|
expression <- readStringForParser readCmdWord
|
||||||
subParse startPos readArithmeticContents expression
|
subParse startPos readArithmeticContents expression
|
||||||
|
|
||||||
|
-- bash allows a=(b), ksh allows $a=(b). dash allows neither. Let's warn.
|
||||||
|
readEvalSuffix = many1 (readIoRedirect <|> readCmdWord <|> evalFallback)
|
||||||
|
where
|
||||||
|
evalFallback = do
|
||||||
|
pos <- getPosition
|
||||||
|
lookAhead $ char '('
|
||||||
|
parseProblemAt pos WarningC 1098 "Quote/escape special characters when using eval, e.g. eval \"a=(b)\"."
|
||||||
|
fail "Unexpected parentheses. Make sure to quote when eval'ing as shell parsers differ."
|
||||||
|
|
||||||
-- Get whatever a parser would parse as a string
|
-- Get whatever a parser would parse as a string
|
||||||
readStringForParser parser = do
|
readStringForParser parser = do
|
||||||
pos <- lookAhead (parser >> getPosition)
|
pos <- lookAhead (parser >> getPosition)
|
||||||
|
Reference in New Issue
Block a user