File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2625,8 +2625,10 @@ prop_checkGlobsAsOptions3 = verifyNot checkGlobsAsOptions "rm -- *.txt"
26252625prop_checkGlobsAsOptions4 = verifyNot checkGlobsAsOptions " *.txt"
26262626prop_checkGlobsAsOptions5 = verifyNot checkGlobsAsOptions " echo 'Files:' *.txt"
26272627prop_checkGlobsAsOptions6 = verifyNot checkGlobsAsOptions " printf '%s\\ n' *"
2628- checkGlobsAsOptions _ cmd@ (T_SimpleCommand _ _ args) =
2629- unless ((fromMaybe " " $ getCommandBasename cmd) `elem` [" echo" , " printf" ]) $
2628+ prop_checkGlobsAsOptions7 = verifyNot checkGlobsAsOptions " set -f; ls *"
2629+ prop_checkGlobsAsOptions8 = verifyNot checkGlobsAsOptions " set -o noglob\n rm *"
2630+ checkGlobsAsOptions params cmd@ (T_SimpleCommand _ _ args) =
2631+ unless (((fromMaybe " " $ getCommandBasename cmd) `elem` [" echo" , " printf" ]) || hasNoglob params) $
26302632 mapM_ check $ takeWhile (not . isEndOfArgs) (drop 1 args)
26312633 where
26322634 check v@ (T_NormalWord _ (T_Glob id s: _)) | s == " *" || s == " ?" =
Original file line number Diff line number Diff line change @@ -87,6 +87,8 @@ data Parameters = Parameters {
8787 hasInheritErrexit :: Bool ,
8888 -- Whether this script has 'set -e' anywhere.
8989 hasSetE :: Bool ,
90+ -- Whether this script has 'set -f' or 'set -o noglob' anywhere.
91+ hasNoglob :: Bool ,
9092 -- Whether this script has 'set -o pipefail' anywhere.
9193 hasPipefail :: Bool ,
9294 -- Whether this script has 'shopt -s execfail' anywhere.
@@ -207,6 +209,7 @@ makeParameters spec = params
207209 rootNode = root,
208210 shellType = fromMaybe (determineShell (asFallbackShell spec) root) $ asShellType spec,
209211 hasSetE = containsSetE root,
212+ hasNoglob = containsNoglob root,
210213 hasLastpipe =
211214 case shellType params of
212215 Bash -> isOptionSet " lastpipe" root
@@ -262,6 +265,17 @@ containsSetE root = isNothing $ doAnalysis (guard . not . isSetE) root
262265 _ -> False
263266 re = mkRegex " [[:space:]]-[^-]*e"
264267
268+ containsNoglob root = isNothing $ doAnalysis (guard . not . isNoglob) root
269+ where
270+ isNoglob t =
271+ case t of
272+ T_Script _ (T_Literal _ str) _ -> str `matches` re
273+ T_SimpleCommand {} ->
274+ t `isUnqualifiedCommand` " set" &&
275+ (" noglob" `elem` oversimplify t ||
276+ " f" `elem` map snd (getAllFlags t))
277+ _ -> False
278+ re = mkRegex " [[:space:]]-[^-]*f"
265279
266280containsSetOption opt root = isNothing $ doAnalysis (guard . not . isPipefail) root
267281 where
You can’t perform that action at this time.
0 commit comments