diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs index f85e6351..8b67fb2d 100644 --- a/System/FilePath/Internal.hs +++ b/System/FilePath/Internal.hs @@ -642,6 +642,8 @@ splitPath x = [drive | drive /= ""] ++ f path -- > Windows: splitDirectories "C:\\test\\file" == ["C:\\", "test", "file"] -- > Valid x => joinPath (splitDirectories x) `equalFilePath` x -- > splitDirectories "" == [] +-- > Windows: splitDirectories "C:\\test\\\\\\file" == ["C:\\", "test", "file"] +-- > splitDirectories "/test///file" == ["/","test","file"] splitDirectories :: FilePath -> [FilePath] splitDirectories path = if hasDrive path then head pathComponents : f (tail pathComponents) @@ -749,7 +751,10 @@ makeRelative root path -- > Windows: normalise "c:\\file/bob\\" == "C:\\file\\bob\\" -- > Windows: normalise "c:\\" == "C:\\" -- > Windows: normalise "\\\\server\\test" == "\\\\server\\test" +-- > Windows: normalise "//server/test" == "\\\\server\\test" -- > Windows: normalise "c:/file" == "C:\\file" +-- > Windows: normalise "/file" == "\\file" +-- > Windows: normalise "\\" == "\\" -- > normalise "." == "." -- > Posix: normalise "./" == "./" -- > Posix: normalise "./." == "./" @@ -757,7 +762,7 @@ makeRelative root path -- > Posix: normalise "bob/fred/." == "bob/fred/" normalise :: FilePath -> FilePath normalise path = joinDrive' (normaliseDrive drv) (f pth) - ++ [pathSeparator | isDirPath pth] + ++ [pathSeparator | isDirPath pth && length pth > 1] where (drv,pth) = splitDrive path @@ -767,13 +772,10 @@ normalise path = joinDrive' (normaliseDrive drv) (f pth) isDirPath xs = hasTrailingPathSeparator xs || not (null xs) && last xs == '.' && hasTrailingPathSeparator (init xs) - f = joinPath . dropDots . splitDirectories . propSep + f = joinPath . dropDots . propSep . splitDirectories - propSep (a:b:xs) - | isPathSeparator a && isPathSeparator b = propSep (a:xs) - propSep (a:xs) - | isPathSeparator a = pathSeparator : propSep xs - propSep (x:xs) = x : propSep xs + propSep (x:xs) | all isPathSeparator x = [pathSeparator] : xs + | otherwise = x : xs propSep [] = [] dropDots = filter ("." /=) @@ -782,7 +784,7 @@ normaliseDrive :: FilePath -> FilePath normaliseDrive drive | isPosix = drive normaliseDrive drive = if isJust $ readDriveLetter x2 then map toUpper x2 - else drive + else x2 where x2 = map repSlash drive diff --git a/changelog.md b/changelog.md index 13dad0e2..3e87a9cf 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,12 @@ * Bug fix: on Windows, `dropTrailingPathSeparator "/"` now returns `"/"` unchanged, instead of the normalised `"\\"`. + * Bug fix: on Windows, `normalise "\\"` now retuns `"\\"` unchanged, + instead of `"\\\\"`. + + * Bug fix: on Windows, `normalise "//server/test"` now retuns + `"\\\\server\\test"`, instead of `"//server/test"` unchanged. + ## 1.3.0.2 *Mar 2014* * Bundled with GHC 7.8.1