Warn about non-posix %q and flags for printf.

This commit is contained in:
Vidar Holen 2015-10-10 20:14:17 -07:00
parent 5aaa1a7d9a
commit 58d45e3fa4
1 changed files with 9 additions and 0 deletions

View File

@ -584,6 +584,8 @@ prop_checkBashisms26= verify checkBashisms "trap mything ERR SIGTERM"
prop_checkBashisms27= verify checkBashisms "echo *[^0-9]*" prop_checkBashisms27= verify checkBashisms "echo *[^0-9]*"
prop_checkBashisms28= verify checkBashisms "exec {n}>&2" prop_checkBashisms28= verify checkBashisms "exec {n}>&2"
prop_checkBashisms29= verify checkBashisms "echo ${!var}" prop_checkBashisms29= verify checkBashisms "echo ${!var}"
prop_checkBashisms30= verify checkBashisms "printf -v '%s' \"$1\""
prop_checkBashisms31= verify checkBashisms "printf '%q' \"$1\""
checkBashisms _ = bashism checkBashisms _ = bashism
where where
errMsg id s = err id 2040 $ "In sh, " ++ s ++ " not supported, even when sh is actually bash." errMsg id s = err id 2040 $ "In sh, " ++ s ++ " not supported, even when sh is actually bash."
@ -671,6 +673,12 @@ checkBashisms _ = bashism
return $ warnMsg (getId token) $ "trapping " ++ word ++ " is" return $ warnMsg (getId token) $ "trapping " ++ word ++ " is"
in in
mapM_ check (reverse rest) mapM_ check (reverse rest)
when (name == "printf") $ potentially $ do
format <- rest !!! 0 -- flags are covered by allowedFlags
let literal = onlyLiteralString format
guard $ "%q" `isInfixOf` literal
return $ warnMsg (getId format) "printf %q is"
where where
bashCommands = [ bashCommands = [
"let", "caller", "builtin", "complete", "compgen", "declare", "dirs", "disown", "let", "caller", "builtin", "complete", "compgen", "declare", "dirs", "disown",
@ -681,6 +689,7 @@ checkBashisms _ = bashism
("read", ["r"]), ("read", ["r"]),
("ulimit", ["f"]), ("ulimit", ["f"]),
("echo", []), ("echo", []),
("printf", []),
("exec", []) ("exec", [])
] ]