Merge pull request #3 from snoyberg/master
Handle parent directory checks on Windows
This commit is contained in:
commit
30890ad3c2
30
src/Path.hs
30
src/Path.hs
@ -83,9 +83,7 @@ parseAbsDir filepath =
|
|||||||
if FilePath.isAbsolute filepath &&
|
if FilePath.isAbsolute filepath &&
|
||||||
not (null (normalizeDir filepath)) &&
|
not (null (normalizeDir filepath)) &&
|
||||||
not (isPrefixOf "~/" filepath) &&
|
not (isPrefixOf "~/" filepath) &&
|
||||||
not (isSuffixOf "/.." filepath) &&
|
not (hasParentDir filepath) &&
|
||||||
not (isInfixOf "/../" filepath) &&
|
|
||||||
not (isPrefixOf "../" filepath)
|
|
||||||
then return (Path (normalizeDir filepath))
|
then return (Path (normalizeDir filepath))
|
||||||
else throwM (InvalidAbsDir filepath)
|
else throwM (InvalidAbsDir filepath)
|
||||||
|
|
||||||
@ -100,9 +98,7 @@ parseRelDir filepath =
|
|||||||
if not (FilePath.isAbsolute filepath) &&
|
if not (FilePath.isAbsolute filepath) &&
|
||||||
not (null filepath) &&
|
not (null filepath) &&
|
||||||
not (isPrefixOf "~/" filepath) &&
|
not (isPrefixOf "~/" filepath) &&
|
||||||
not (isPrefixOf "../" filepath) &&
|
not (hasParentDir filepath) &&
|
||||||
not (isSuffixOf "/.." filepath) &&
|
|
||||||
not (isInfixOf "/../" filepath) &&
|
|
||||||
not (null (normalizeDir filepath)) &&
|
not (null (normalizeDir filepath)) &&
|
||||||
filepath /= ".."
|
filepath /= ".."
|
||||||
then return (Path (normalizeDir filepath))
|
then return (Path (normalizeDir filepath))
|
||||||
@ -118,9 +114,7 @@ parseAbsFile filepath =
|
|||||||
if FilePath.isAbsolute filepath &&
|
if FilePath.isAbsolute filepath &&
|
||||||
not (FilePath.hasTrailingPathSeparator filepath) &&
|
not (FilePath.hasTrailingPathSeparator filepath) &&
|
||||||
not (isPrefixOf "~/" filepath) &&
|
not (isPrefixOf "~/" filepath) &&
|
||||||
not (isPrefixOf "../" filepath) &&
|
not (hasParentDir filepath) &&
|
||||||
not (isSuffixOf "/.." filepath) &&
|
|
||||||
not (isInfixOf "/../" filepath) &&
|
|
||||||
not (null (normalizeFile filepath)) &&
|
not (null (normalizeFile filepath)) &&
|
||||||
filepath /= ".."
|
filepath /= ".."
|
||||||
then return (Path (normalizeFile filepath))
|
then return (Path (normalizeFile filepath))
|
||||||
@ -137,15 +131,25 @@ parseRelFile filepath =
|
|||||||
FilePath.hasTrailingPathSeparator filepath) &&
|
FilePath.hasTrailingPathSeparator filepath) &&
|
||||||
not (null filepath) &&
|
not (null filepath) &&
|
||||||
not (isPrefixOf "~/" filepath) &&
|
not (isPrefixOf "~/" filepath) &&
|
||||||
not (isPrefixOf "../" filepath) &&
|
not (hasParentDir filepath) &&
|
||||||
not (isInfixOf "/../" filepath) &&
|
|
||||||
not (isSuffixOf "/.." filepath) &&
|
|
||||||
not (isInfixOf "/../" filepath) &&
|
|
||||||
not (null (normalizeFile filepath)) &&
|
not (null (normalizeFile filepath)) &&
|
||||||
filepath /= ".."
|
filepath /= ".."
|
||||||
then return (Path (normalizeFile filepath))
|
then return (Path (normalizeFile filepath))
|
||||||
else throwM (InvalidRelFile 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
|
-- Constructors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user