From 04608e0e53e36fad44ff5503fa1f915870582a08 Mon Sep 17 00:00:00 2001 From: Chris Done Date: Fri, 4 Mar 2016 15:06:27 +0100 Subject: [PATCH] Reject only .. and . (#13) --- src/Path.hs | 6 +++--- test/Main.hs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Path.hs b/src/Path.hs index 21c8829..ed19c23 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -117,7 +117,7 @@ parseRelDir filepath = not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeDir filepath)) && - not (all (== '.') filepath) && + filepath /= "." && filepath /= ".." && FilePath.isValid filepath then return (Path (normalizeDir filepath)) else throwM (InvalidRelDir filepath) @@ -134,7 +134,7 @@ parseAbsFile filepath = not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeFile filepath)) && - not (all (== '.') filepath) && + filepath /= "." && filepath /= ".." && FilePath.isValid filepath then return (Path (normalizeFile filepath)) else throwM (InvalidAbsFile filepath) @@ -154,7 +154,7 @@ parseRelFile filepath = not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeFile filepath)) && - not (all (== '.') filepath) && + filepath /= "." && filepath /= ".." && FilePath.isValid filepath then return (Path (normalizeFile filepath)) else throwM (InvalidRelFile filepath) diff --git a/test/Main.hs b/test/Main.hs index b78f56b..305e1db 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -156,6 +156,7 @@ parseRelDirSpec = failing "///foo//bar//mu/" failing "///foo//bar////mu" failing "///foo//bar/.//mu" + succeeding "..." (Path "...") succeeding "foo.bak" (Path "foo.bak/") succeeding "./foo" (Path "foo/") succeeding "././foo" (Path "foo/") @@ -176,6 +177,7 @@ parseAbsFileSpec = failing "/" failing "//" failing "///foo//bar//mu/" + succeeding "..." (Path "...") succeeding "/foo.txt" (Path "/foo.txt") succeeding "///foo//bar////mu.txt" (Path "/foo/bar/mu.txt") succeeding "///foo//bar/.//mu.txt" (Path "/foo/bar/mu.txt") @@ -195,6 +197,7 @@ parseRelFileSpec = failing "///foo//bar//mu/" failing "///foo//bar////mu" failing "///foo//bar/.//mu" + succeeding "..." (Path "...") succeeding "foo.txt" (Path "foo.txt") succeeding "./foo.txt" (Path "foo.txt") succeeding "././foo.txt" (Path "foo.txt")