Assume variables have spaces/globs by default
This commit is contained in:
parent
4853dce3fe
commit
a89aee1a34
|
@ -1550,13 +1550,11 @@ prop_checkSpacefulnessJ = verifyFull checkSpacefulness "echo $PWD"
|
||||||
checkSpacefulness t =
|
checkSpacefulness t =
|
||||||
doVariableFlowAnalysis readF writeF (Map.fromList defaults) t
|
doVariableFlowAnalysis readF writeF (Map.fromList defaults) t
|
||||||
where
|
where
|
||||||
defaults =
|
defaults = zip variablesWithoutSpaces (repeat False)
|
||||||
let values = ["PWD"] ++ (map show [0..10]) in
|
|
||||||
zip values (repeat True)
|
|
||||||
|
|
||||||
hasSpaces name = do
|
hasSpaces name = do
|
||||||
map <- get
|
map <- get
|
||||||
return $ Map.findWithDefault False name map
|
return $ Map.findWithDefault True name map
|
||||||
|
|
||||||
setSpaces name bool = do
|
setSpaces name bool = do
|
||||||
modify $ Map.insert name bool
|
modify $ Map.insert name bool
|
||||||
|
@ -1564,6 +1562,8 @@ checkSpacefulness t =
|
||||||
readF _ token name = do
|
readF _ token name = do
|
||||||
spaced <- hasSpaces name
|
spaced <- hasSpaces name
|
||||||
if spaced
|
if spaced
|
||||||
|
&& (not $ "@" `isPrefixOf` name) -- There's another warning for this
|
||||||
|
&& (not $ isCounting token)
|
||||||
&& (not $ inUnquotableContext parents token)
|
&& (not $ inUnquotableContext parents token)
|
||||||
&& (not $ usedAsCommandName parents token)
|
&& (not $ usedAsCommandName parents token)
|
||||||
then return [(getId token, Note InfoC 2086 warning)]
|
then return [(getId token, Note InfoC 2086 warning)]
|
||||||
|
@ -1578,13 +1578,19 @@ checkSpacefulness t =
|
||||||
writeF _ _ name (DataFrom vals) = do
|
writeF _ _ name (DataFrom vals) = do
|
||||||
map <- get
|
map <- get
|
||||||
setSpaces name
|
setSpaces name
|
||||||
(isSpacefulWord (\x -> Map.findWithDefault False x map) vals)
|
(isSpacefulWord (\x -> Map.findWithDefault True x map) vals)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
parents = getParentTree t
|
parents = getParentTree t
|
||||||
|
|
||||||
|
isCounting (T_DollarBraced id token) =
|
||||||
|
case concat $ deadSimple token of
|
||||||
|
'#':_ -> True
|
||||||
|
_ -> False
|
||||||
|
isCounting _ = False
|
||||||
|
|
||||||
isSpacefulWord :: (String -> Bool) -> [Token] -> Bool
|
isSpacefulWord :: (String -> Bool) -> [Token] -> Bool
|
||||||
isSpacefulWord f words =
|
isSpacefulWord f words = any (isSpaceful f) words
|
||||||
any (isSpaceful f) words
|
|
||||||
isSpaceful :: (String -> Bool) -> Token -> Bool
|
isSpaceful :: (String -> Bool) -> Token -> Bool
|
||||||
isSpaceful spacefulF x =
|
isSpaceful spacefulF x =
|
||||||
case x of
|
case x of
|
||||||
|
|
|
@ -40,6 +40,13 @@ internalVariables = [
|
||||||
"ZLE_REMOVE_SUFFIX_CHARS", "ZLE_SPACE_SUFFIX_CHARS"
|
"ZLE_REMOVE_SUFFIX_CHARS", "ZLE_SPACE_SUFFIX_CHARS"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
variablesWithoutSpaces = [
|
||||||
|
"$", "-", "?", "!",
|
||||||
|
"BASHPID", "BASH_ARGC", "BASH_LINENO", "BASH_SUBSHELL", "EUID", "LINENO",
|
||||||
|
"OPTIND", "PPID", "PWD", "RANDOM", "SECONDS", "SHELLOPTS", "SHLVL", "UID",
|
||||||
|
"COLUMNS", "HISTFILESIZE", "HISTSIZE", "LINES"
|
||||||
|
]
|
||||||
|
|
||||||
commonCommands = [
|
commonCommands = [
|
||||||
"admin", "alias", "ar", "asa", "at", "awk", "basename", "batch",
|
"admin", "alias", "ar", "asa", "at", "awk", "basename", "batch",
|
||||||
"bc", "bg", "break", "c99", "cal", "cat", "cd", "cflow", "chgrp",
|
"bc", "bg", "break", "c99", "cal", "cat", "cd", "cflow", "chgrp",
|
||||||
|
|
Loading…
Reference in New Issue