path 0.5.0 → 0.5.1
raw patch · 2 files changed
+18/−14 lines, 2 files
Files
- path.cabal +1/−1
- src/Path.hs +17/−13
path.cabal view
@@ -1,5 +1,5 @@ name: path-version: 0.5.0+version: 0.5.1 synopsis: Path description: Path license: BSD3
src/Path.hs view
@@ -83,9 +83,7 @@ if FilePath.isAbsolute filepath && not (null (normalizeDir filepath)) && not (isPrefixOf "~/" filepath) &&- not (isSuffixOf "/.." filepath) &&- not (isInfixOf "/../" filepath) &&- not (isPrefixOf "../" filepath)+ not (hasParentDir filepath) then return (Path (normalizeDir filepath)) else throwM (InvalidAbsDir filepath) @@ -100,9 +98,7 @@ if not (FilePath.isAbsolute filepath) && not (null filepath) && not (isPrefixOf "~/" filepath) &&- not (isPrefixOf "../" filepath) &&- not (isSuffixOf "/.." filepath) &&- not (isInfixOf "/../" filepath) &&+ not (hasParentDir filepath) && not (null (normalizeDir filepath)) && filepath /= ".." then return (Path (normalizeDir filepath))@@ -118,9 +114,7 @@ if FilePath.isAbsolute filepath && not (FilePath.hasTrailingPathSeparator filepath) && not (isPrefixOf "~/" filepath) &&- not (isPrefixOf "../" filepath) &&- not (isSuffixOf "/.." filepath) &&- not (isInfixOf "/../" filepath) &&+ not (hasParentDir filepath) && not (null (normalizeFile filepath)) && filepath /= ".." then return (Path (normalizeFile filepath))@@ -137,14 +131,24 @@ FilePath.hasTrailingPathSeparator filepath) && not (null filepath) && not (isPrefixOf "~/" filepath) &&- not (isPrefixOf "../" filepath) &&- not (isInfixOf "/../" filepath) &&- not (isSuffixOf "/.." filepath) &&- not (isInfixOf "/../" filepath) &&+ not (hasParentDir filepath) && not (null (normalizeFile filepath)) && filepath /= ".." then return (Path (normalizeFile filepath)) else throwM (InvalidRelFile filepath)++-- | Helper function: check if the filepath has any parent directories in it.+-- This handles the logic of checking for different path separators on Windows.+hasParentDir :: FilePath -> Bool+hasParentDir filepath' =+ (isSuffixOf "/.." filepath) ||+ (isInfixOf "/../" filepath) ||+ (isPrefixOf "../" filepath)+ where+ filepath =+ case FilePath.pathSeparator of+ '/' -> filepath'+ x -> map (\y -> if x == y then '/' else y) filepath' -------------------------------------------------------------------------------- -- Constructors