diff --git a/yesod-routes/Yesod/Routes/Overlap.hs b/yesod-routes/Yesod/Routes/Overlap.hs index 67b37c2f..aa116b04 100644 --- a/yesod-routes/Yesod/Routes/Overlap.hs +++ b/yesod-routes/Yesod/Routes/Overlap.hs @@ -25,15 +25,28 @@ hasSuffix r = Methods Nothing _ -> False overlaps :: [(CheckOverlap, Piece t)] -> [(CheckOverlap, Piece t)] -> Bool -> Bool -> Bool -overlaps [] [] False False = False + +-- No pieces on either side, will overlap regardless of suffix +overlaps [] [] _ _ = True + +-- No pieces on the left, will overlap if the left side has a suffix overlaps [] _ suffixX _ = suffixX + +-- Ditto for the right overlaps _ [] _ suffixY = suffixY -overlaps ((False, _):xs) (_:ys) suffixX suffixY = overlaps xs ys suffixX suffixY -overlaps (_:xs) ((False, _):ys) suffixX suffixY = overlaps xs ys suffixX suffixY + +-- As soon as we ignore a single piece (via CheckOverlap == False), we say that +-- the routes don't overlap at all. In other words, disabling overlap checking +-- on a single piece disables it on the whole route. +overlaps ((False, _):_) _ _ _ = False +overlaps _ ((False, _):_) _ _ = False + +-- Compare the actual pieces overlaps ((True, pieceX):xs) ((True, pieceY):ys) suffixX suffixY = - piecesOverlap pieceX pieceY || overlaps xs ys suffixX suffixY + piecesOverlap pieceX pieceY && overlaps xs ys suffixX suffixY piecesOverlap :: Piece t -> Piece t -> Bool +-- Statics only match if they equal. Dynamics match with anything piecesOverlap (Static x) (Static y) = x == y piecesOverlap _ _ = True diff --git a/yesod-routes/test/main.hs b/yesod-routes/test/main.hs index 51f5d260..33e03997 100644 --- a/yesod-routes/test/main.hs +++ b/yesod-routes/test/main.hs @@ -306,6 +306,13 @@ main = hspecX $ do /foo Foo1 /#!String Foo2 /!foo Foo3 +|] + findOverlapNames routes @?= [] + it "proper boolean logic" $ do + let routes = [parseRoutesNoCheck| +/foo/bar Foo1 +/foo/baz Foo2 +/bar/baz Foo3 |] findOverlapNames routes @?= []