Make `read -t 0` test more forgiving towards other flags
This commit is contained in:
parent
91abd979f2
commit
7473d4a743
|
@ -2809,10 +2809,19 @@ prop_checkReadWithoutR1 = verify checkReadWithoutR "read -a foo"
|
||||||
prop_checkReadWithoutR2 = verifyNot checkReadWithoutR "read -ar foo"
|
prop_checkReadWithoutR2 = verifyNot checkReadWithoutR "read -ar foo"
|
||||||
prop_checkReadWithoutR3 = verifyNot checkReadWithoutR "read -t 0"
|
prop_checkReadWithoutR3 = verifyNot checkReadWithoutR "read -t 0"
|
||||||
prop_checkReadWithoutR4 = verifyNot checkReadWithoutR "read -t 0 && read --d '' -r bar"
|
prop_checkReadWithoutR4 = verifyNot checkReadWithoutR "read -t 0 && read --d '' -r bar"
|
||||||
prop_checkReadWithoutR5 = verify checkReadWithoutR "read -t 0 foo < file.txt"
|
prop_checkReadWithoutR5 = verifyNot checkReadWithoutR "read -t 0 foo < file.txt"
|
||||||
|
prop_checkReadWithoutR6 = verifyNot checkReadWithoutR "read -u 3 -t 0"
|
||||||
checkReadWithoutR _ t@T_SimpleCommand {} | t `isUnqualifiedCommand` "read" =
|
checkReadWithoutR _ t@T_SimpleCommand {} | t `isUnqualifiedCommand` "read" =
|
||||||
unless (oversimplify t == ["read", "-t", "0"] || "r" `elem` map snd (getAllFlags t)) $
|
unless ("r" `elem` map snd flags || has_t0) $
|
||||||
info (getId $ getCommandTokenOrThis t) 2162 "read without -r will mangle backslashes."
|
info (getId $ getCommandTokenOrThis t) 2162 "read without -r will mangle backslashes."
|
||||||
|
where
|
||||||
|
flags = getAllFlags t
|
||||||
|
has_t0 = fromMaybe False $ do
|
||||||
|
parsed <- getOpts flagsForRead flags
|
||||||
|
t <- getOpt "t" parsed
|
||||||
|
str <- getLiteralString t
|
||||||
|
return $ str == "0"
|
||||||
|
|
||||||
checkReadWithoutR _ _ = return ()
|
checkReadWithoutR _ _ = return ()
|
||||||
|
|
||||||
prop_checkUncheckedCd1 = verifyTree checkUncheckedCdPushdPopd "cd ~/src; rm -r foo"
|
prop_checkUncheckedCd1 = verifyTree checkUncheckedCdPushdPopd "cd ~/src; rm -r foo"
|
||||||
|
|
|
@ -932,12 +932,11 @@ isQuotedAlternativeReference t =
|
||||||
-- Just [("r", -re), ("e", -re), ("d", :), ("u", 3), ("", bar)]
|
-- Just [("r", -re), ("e", -re), ("d", :), ("u", 3), ("", bar)]
|
||||||
-- where flags with arguments map to arguments, while others map to themselves.
|
-- where flags with arguments map to arguments, while others map to themselves.
|
||||||
-- Any unrecognized flag will result in Nothing.
|
-- Any unrecognized flag will result in Nothing.
|
||||||
getGnuOpts = getOpts getAllFlags
|
getGnuOpts str t = getOpts str $ getAllFlags t
|
||||||
getBsdOpts = getOpts getLeadingFlags
|
getBsdOpts str t = getOpts str $ getLeadingFlags t
|
||||||
getOpts :: (Token -> [(Token, String)]) -> String -> Token -> Maybe [(String, Token)]
|
getOpts :: String -> [(Token, String)] -> Maybe [(String, Token)]
|
||||||
getOpts flagTokenizer string cmd = process flags
|
getOpts string flags = process flags
|
||||||
where
|
where
|
||||||
flags = flagTokenizer cmd
|
|
||||||
flagList (c:':':rest) = ([c], True) : flagList rest
|
flagList (c:':':rest) = ([c], True) : flagList rest
|
||||||
flagList (c:rest) = ([c], False) : flagList rest
|
flagList (c:rest) = ([c], False) : flagList rest
|
||||||
flagList [] = []
|
flagList [] = []
|
||||||
|
@ -959,6 +958,8 @@ getOpts flagTokenizer string cmd = process flags
|
||||||
more <- process rest2
|
more <- process rest2
|
||||||
return $ (flag1, token1) : more
|
return $ (flag1, token1) : more
|
||||||
|
|
||||||
|
getOpt str flags = snd <$> (listToMaybe $ filter (\(f, _) -> f == str) $ flags)
|
||||||
|
|
||||||
supportsArrays shell = shell == Bash || shell == Ksh
|
supportsArrays shell = shell == Bash || shell == Ksh
|
||||||
|
|
||||||
-- Returns true if the shell is Bash or Ksh (sorry for the name, Ksh)
|
-- Returns true if the shell is Bash or Ksh (sorry for the name, Ksh)
|
||||||
|
|
|
@ -676,7 +676,7 @@ prop_checkReadExpansions7 = verifyNot checkReadExpansions "read $1"
|
||||||
prop_checkReadExpansions8 = verifyNot checkReadExpansions "read ${var?}"
|
prop_checkReadExpansions8 = verifyNot checkReadExpansions "read ${var?}"
|
||||||
checkReadExpansions = CommandCheck (Exactly "read") check
|
checkReadExpansions = CommandCheck (Exactly "read") check
|
||||||
where
|
where
|
||||||
options = getGnuOpts "sreu:n:N:i:p:a:"
|
options = getGnuOpts flagsForRead
|
||||||
getVars cmd = fromMaybe [] $ do
|
getVars cmd = fromMaybe [] $ do
|
||||||
opts <- options cmd
|
opts <- options cmd
|
||||||
return . map snd $ filter (\(x,_) -> x == "" || x == "a") opts
|
return . map snd $ filter (\(x,_) -> x == "" || x == "a") opts
|
||||||
|
|
|
@ -136,3 +136,5 @@ shellForExecutable name =
|
||||||
"ksh88" -> return Ksh
|
"ksh88" -> return Ksh
|
||||||
"ksh93" -> return Ksh
|
"ksh93" -> return Ksh
|
||||||
otherwise -> Nothing
|
otherwise -> Nothing
|
||||||
|
|
||||||
|
flagsForRead = "sreu:n:N:i:p:a:t:"
|
||||||
|
|
Loading…
Reference in New Issue