Warn when using unescaped parens in eval.

This commit is contained in:
Vidar Holen 2015-09-02 21:11:39 -07:00
parent 01c27dc96a
commit 7f547cc0ec
1 changed files with 11 additions and 1 deletions

View File

@ -1484,7 +1484,8 @@ readSimpleCommand = called "simple command" $ do
suffix <- option [] $ getParser readCmdSuffix cmd [
(["declare", "export", "local", "readonly", "typeset"], readModifierSuffix),
(["time"], readTimeSuffix),
(["let"], readLetSuffix)
(["let"], readLetSuffix),
(["eval"], readEvalSuffix)
]
let result = makeSimpleCommand id1 id2 prefix [cmd] suffix
@ -2013,6 +2014,15 @@ readLetSuffix = many1 (readIoRedirect <|> try readLetExpression <|> readCmdWord)
expression <- readStringForParser readCmdWord
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
readStringForParser parser = do
pos <- lookAhead (parser >> getPosition)