mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-06 21:11:35 -07:00
Warn about read foo[i]
expanding as glob (fixes #2345)
This commit is contained in:
parent
05bdeae3ab
commit
205ba429b3
3 changed files with 24 additions and 4 deletions
|
@ -2689,12 +2689,13 @@ prop_checkCharRangeGlob1 = verify checkCharRangeGlob "ls *[:digit:].jpg"
|
|||
prop_checkCharRangeGlob2 = verifyNot checkCharRangeGlob "ls *[[:digit:]].jpg"
|
||||
prop_checkCharRangeGlob3 = verify checkCharRangeGlob "ls [10-15]"
|
||||
prop_checkCharRangeGlob4 = verifyNot checkCharRangeGlob "ls [a-zA-Z]"
|
||||
prop_checkCharRangeGlob5 = verifyNot checkCharRangeGlob "tr -d [a-zA-Z]" -- tr has 2060
|
||||
prop_checkCharRangeGlob5 = verifyNot checkCharRangeGlob "tr -d [aa]" -- tr has 2060
|
||||
prop_checkCharRangeGlob6 = verifyNot checkCharRangeGlob "[[ $x == [!!]* ]]"
|
||||
prop_checkCharRangeGlob7 = verifyNot checkCharRangeGlob "[[ -v arr[keykey] ]]"
|
||||
prop_checkCharRangeGlob8 = verifyNot checkCharRangeGlob "[[ arr[keykey] -gt 1 ]]"
|
||||
prop_checkCharRangeGlob9 = verifyNot checkCharRangeGlob "read arr[keykey]" -- tr has 2313
|
||||
checkCharRangeGlob p t@(T_Glob id str) |
|
||||
isCharClass str && not (isParamTo (parentMap p) "tr" t) && not (isDereferenced t) =
|
||||
isCharClass str && not isIgnoredCommand && not (isDereferenced t) =
|
||||
if ":" `isPrefixOf` contents
|
||||
&& ":" `isSuffixOf` contents
|
||||
&& contents /= ":"
|
||||
|
@ -2712,6 +2713,10 @@ checkCharRangeGlob p t@(T_Glob id str) |
|
|||
'^':rest -> rest
|
||||
x -> x
|
||||
|
||||
isIgnoredCommand = fromMaybe False $ do
|
||||
cmd <- getClosestCommand (parentMap p) t
|
||||
return $ isCommandMatch cmd (`elem` ["tr", "read"])
|
||||
|
||||
-- Check if this is a dereferencing context like [[ -v array[operandhere] ]]
|
||||
isDereferenced = fromMaybe False . msum . map isDereferencingOp . getPath (parentMap p)
|
||||
isDereferencingOp t =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue