[commit: packages/filepath] master: Bug fix: normalise "/./" == "/" on Posix, "\\" on Windows (f7869ab)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:35:27 UTC 2015


Repository : ssh://git@git.haskell.org/filepath

On branch  : master
Link       : http://git.haskell.org/packages/filepath.git/commitdiff/f7869ab03c0759c6035c2bbb025eb5df4ab8e92f

>---------------------------------------------------------------

commit f7869ab03c0759c6035c2bbb025eb5df4ab8e92f
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Mon Oct 27 16:04:48 2014 +0100

    Bug fix: normalise "/./" == "/" on Posix, "\\" on Windows


>---------------------------------------------------------------

f7869ab03c0759c6035c2bbb025eb5df4ab8e92f
 System/FilePath/Internal.hs | 9 +++++++--
 changelog.md                | 3 +++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index b748b52..5014c48 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -736,20 +736,25 @@ makeRelative root path
 -- > Windows: normalise "c:/file" == "C:\\file"
 -- > Windows: normalise "/file" == "\\file"
 -- > Windows: normalise "\\" == "\\"
+-- > Windows: normalise "/./" == "\\"
 -- >          normalise "." == "."
 -- > Posix:   normalise "./" == "./"
 -- > Posix:   normalise "./." == "./"
+-- > Posix:   normalise "/./" == "/"
 -- > Posix:   normalise "/" == "/"
 -- > Posix:   normalise "bob/fred/." == "bob/fred/"
 normalise :: FilePath -> FilePath
-normalise path = joinDrive' (normaliseDrive drv) (f pth)
-              ++ [pathSeparator | isDirPath pth && length pth > 1]
+normalise path = result ++ [pathSeparator | addPathSeparator]
     where
         (drv,pth) = splitDrive path
+        result = joinDrive' (normaliseDrive drv) (f pth)
 
         joinDrive' "" "" = "."
         joinDrive' d p = joinDrive d p
 
+        addPathSeparator = isDirPath pth
+            && not (hasTrailingPathSeparator result)
+
         isDirPath xs = hasTrailingPathSeparator xs
             || not (null xs) && last xs == '.' && hasTrailingPathSeparator (init xs)
 
diff --git a/changelog.md b/changelog.md
index 9303b4b..5fda80a 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,9 @@
   * Semantic change: `joinDrive "/foo" "bar"` now returns `"/foo/bar"`,
     instead of `"/foobar"`.
 
+  * Bug fix, `normalise "/./"` now returns "/" on Posix and "\\" on Windows,
+    instead of "//" and "\\\\".
+
   * Bug fix: `isDrive ""` now retuns `False`, instead of `True`.
 
   * Bug fix: on Windows, `dropTrailingPathSeparator "/"` now returns `"/"`



More information about the ghc-commits mailing list