From 59fafe0596ef4cdc26a9baf3d794ec3e507f6ced Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Tue, 17 Apr 2012 14:02:05 +0200 Subject: [PATCH 1/3] Remove infinite loop on MatchGroup without common prefix. In that case, the exact same MatchGroup would be fed to simplifyTerms again. Now, it is returned immediately, and only the rest of the terms are simplified. --- System/FilePath/GlobPattern.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/System/FilePath/GlobPattern.hs b/System/FilePath/GlobPattern.hs index 7299de0..91b1f09 100644 --- a/System/FilePath/GlobPattern.hs +++ b/System/FilePath/GlobPattern.hs @@ -117,8 +117,9 @@ simplifyTerms (MatchClass True (SRange a@[_] []):as) = simplifyTerms (MatchGroup []:as) = simplifyTerms as simplifyTerms (MatchGroup gs:as) = case commonPrefix gs of - (p,[]) -> simplifyTerms (MatchLiteral p : as) - (p,ss) -> simplifyTerms (MatchLiteral p : MatchGroup ss : as) + (p ,[]) -> simplifyTerms (MatchLiteral p : as) + ("",ss) -> MatchGroup ss : simplifyTerms as + (p ,ss) -> simplifyTerms (MatchLiteral p : MatchGroup ss : as) simplifyTerms (a:as) = a:simplifyTerms as commonPrefix :: [String] -> (String, [String]) From 9fd07bfa9b6321743199e44d6e7df5e765d21045 Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Tue, 17 Apr 2012 15:33:44 +0200 Subject: [PATCH 2/3] Fixed matching of groups. Matching of the tail of all groups would continue if any matched, leading to (aa|bb) matching the string ab. Also, any empty group would mean continuing to match the rest of the terms, ignoring a non-empty matching group. This lead to (aa|a) not matching the string a. --- System/FilePath/GlobPattern.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/System/FilePath/GlobPattern.hs b/System/FilePath/GlobPattern.hs index 91b1f09..37af02a 100644 --- a/System/FilePath/GlobPattern.hs +++ b/System/FilePath/GlobPattern.hs @@ -15,6 +15,7 @@ module System.FilePath.GlobPattern ( ) where import Control.Arrow (second) +import Control.Monad (msum) import Data.Ix (Ix, inRange) import Data.List (nub) import Data.Maybe (isJust) @@ -144,11 +145,8 @@ matchTerms (MatchClass k c:ts) cs = matchClass cs >>= matchTerms ts where matchClass (b:bs) | (inClass && k) || not (inClass || k) = return bs where inClass = b `inSRange` c matchClass _ = fail "no match" -matchTerms (MatchGroup g:ts) cs = matchGroup g cs >>= matchTerms ts - where matchGroup g' as | any null g' = return as - matchGroup g' (a:as) | a `elem` map head g' = - matchGroup (map tail g') as - matchGroup _ _ = fail "not in group" +matchTerms (MatchGroup g:ts) cs = msum (map matchGroup g) + where matchGroup g = matchTerms (MatchLiteral g : ts) cs matchTerms [MatchAny] _ = return () matchTerms (MatchAny:ts) cs = matchAny cs >>= matchTerms ts where matchAny [] = fail "no match" From b2c11abf31b532da3074346aa15e56e96a87cd2b Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Tue, 17 Apr 2012 14:06:52 +0200 Subject: [PATCH 3/3] Bump version to 0.3.6.1. --- filemanip.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filemanip.cabal b/filemanip.cabal index 9b600a9..6403417 100644 --- a/filemanip.cabal +++ b/filemanip.cabal @@ -1,5 +1,5 @@ Name: filemanip -Version: 0.3.6.0 +Version: 0.3.6.1 License: BSD3 License-File: LICENSE Author: Bryan O'Sullivan