[commit: packages/filepath] master: Bug fix: pathSeparator can be forward slash on Windows (6ab7023)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:33:53 UTC 2015


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

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

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

commit 6ab7023fb3b8c4ee5305036684dae2d92115c1bc
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Sun Sep 14 21:19:30 2014 +0200

    Bug fix: pathSeparator can be forward slash on Windows
    
    dropTrailingPathSeparator "/" would return "\\" on Windows, since that is the
    default:
    
        pathSeparator = if isWindows then '\\' else '/'
    
    The function `normalise` can be used to normalise pathSeparators in filepaths,
    the function `dropTrailingPathSeparator` shouldn't do it for you.
    
    The test now runs for both Posix as Windows.


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

6ab7023fb3b8c4ee5305036684dae2d92115c1bc
 System/FilePath/Internal.hs | 4 ++--
 changelog.md                | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index 7db6c04..7220804 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -528,14 +528,14 @@ addTrailingPathSeparator x = if hasTrailingPathSeparator x then x else x ++ [pat
 -- | Remove any trailing path separators
 --
 -- > dropTrailingPathSeparator "file/test/" == "file/test"
--- > Posix:    dropTrailingPathSeparator "/" == "/"
+-- >           dropTrailingPathSeparator "/" == "/"
 -- > Windows:  dropTrailingPathSeparator "\\" == "\\"
 -- > Posix:    not (hasTrailingPathSeparator (dropTrailingPathSeparator x)) || isDrive x
 dropTrailingPathSeparator :: FilePath -> FilePath
 dropTrailingPathSeparator x =
     if hasTrailingPathSeparator x && not (isDrive x)
     then let x' = reverse $ dropWhile isPathSeparator $ reverse x
-         in if null x' then [pathSeparator] else x'
+         in if null x' then [last x] else x'
     else x
 
 
diff --git a/changelog.md b/changelog.md
index 2feaf5a..13dad0e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,9 @@
 
   * Bundled with GHC 7.10.1
 
+  * Bug fix: on Windows, `dropTrailingPathSeparator "/"` now returns `"/"`
+    unchanged, instead of the normalised `"\\"`.
+
 ## 1.3.0.2  *Mar 2014*
 
   * Bundled with GHC 7.8.1



More information about the ghc-commits mailing list