Disable UUOC for cat with unquoted variable (fixes #2333)

This commit is contained in:
Vidar Holen 2021-09-25 19:46:27 -07:00
parent 3a296cd788
commit ad92cb4112
2 changed files with 10 additions and 9 deletions

View File

@ -287,14 +287,14 @@ isArrayExpansion (T_DollarBraced _ _ l) =
isArrayExpansion _ = False
-- Is it possible that this arg becomes multiple args?
mayBecomeMultipleArgs t = willBecomeMultipleArgs t || f t
mayBecomeMultipleArgs t = willBecomeMultipleArgs t || f False t
where
f (T_DollarBraced _ _ l) =
f quoted (T_DollarBraced _ _ l) =
let string = concat $ oversimplify l in
"!" `isPrefixOf` string
f (T_DoubleQuoted _ parts) = any f parts
f (T_NormalWord _ parts) = any f parts
f _ = False
not quoted || "!" `isPrefixOf` string
f quoted (T_DoubleQuoted _ parts) = any (f True) parts
f quoted (T_NormalWord _ parts) = any (f quoted) parts
f _ _ = False
-- Is it certain that this word will becomes multiple words?
willBecomeMultipleArgs t = willConcatInAssignment t || f t
@ -302,7 +302,6 @@ willBecomeMultipleArgs t = willConcatInAssignment t || f t
f T_Extglob {} = True
f T_Glob {} = True
f T_BraceExpansion {} = True
f (T_DoubleQuoted _ parts) = any f parts
f (T_NormalWord _ parts) = any f parts
f _ = False

View File

@ -506,7 +506,9 @@ checkWrongArithmeticAssignment _ _ = return ()
prop_checkUuoc1 = verify checkUuoc "cat foo | grep bar"
prop_checkUuoc2 = verifyNot checkUuoc "cat * | grep bar"
prop_checkUuoc3 = verify checkUuoc "cat $var | grep bar"
prop_checkUuoc3 = verify checkUuoc "cat \"$var\" | grep bar"
prop_checkUuoc3b = verifyNot checkUuoc "cat $var | grep bar"
prop_checkUuoc3c = verifyNot checkUuoc "cat \"${!var}\" | grep bar"
prop_checkUuoc4 = verifyNot checkUuoc "cat $var"
prop_checkUuoc5 = verifyNot checkUuoc "cat \"$@\""
prop_checkUuoc6 = verifyNot checkUuoc "cat -n | grep bar"
@ -659,7 +661,7 @@ prop_checkForInQuoted7 = verify checkForInQuoted "for f in ls, grep, mv; do true
prop_checkForInQuoted8 = verify checkForInQuoted "for f in 'ls', 'grep', 'mv'; do true; done"
prop_checkForInQuoted9 = verifyNot checkForInQuoted "for f in 'ls,' 'grep,' 'mv'; do true; done"
checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [word@(T_DoubleQuoted id list)]] _)
| any (\x -> willSplit x && not (mayBecomeMultipleArgs x)) list
| any willSplit list && not (mayBecomeMultipleArgs word)
|| maybe False wouldHaveBeenGlob (getLiteralString word) =
err id 2066 "Since you double quoted this, it will not word split, and the loop will only run once."
checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [T_SingleQuoted id _]] _) =