Merge pull request #1918 from josephcsible/getsuspiciousregexwildcard

Clean up and optimize getSuspiciousRegexWildcard
This commit is contained in:
Vidar Holen
2020-04-12 15:32:00 -07:00
committed by GitHub

View File

@@ -283,15 +283,9 @@ 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
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]\\*|[][^$+\\\\]"