From 163c710ba7da07334999bf18804c971a2be41368 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 12 Apr 2020 16:15:45 -0400 Subject: [PATCH] Clean up and optimize getSuspiciousRegexWildcard --- src/ShellCheck/Checks/Commands.hs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index c68bdd1..395ed2b 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -283,17 +283,11 @@ checkGrepRe = CommandCheck (Basename "grep") check where candidates = sampleWords ++ map (\(x:r) -> toUpper x : r) sampleWords - getSuspiciousRegexWildcard str = - if not $ str `matches` contra - then do - match <- matchRegex suspicious str - str <- match !!! 0 - str !!! 0 - else - fail "looks good" - where - suspicious = mkRegex "([A-Za-z1-9])\\*" - contra = mkRegex "[^a-zA-Z1-9]\\*|[][^$+\\\\]" + getSuspiciousRegexWildcard str = case matchRegex suspicious str of + Just [[c]] | not (str `matches` contra) -> Just c + _ -> fail "looks good" + suspicious = mkRegex "([A-Za-z1-9])\\*" + contra = mkRegex "[^a-zA-Z1-9]\\*|[][^$+\\\\]" prop_checkTrapQuotes1 = verify checkTrapQuotes "trap \"echo $num\" INT"