[commit: packages/filepath] master: Bug fix: equalFilePath "C:\\" "C:" == False (bdc0446)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:34:03 UTC 2015


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

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

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

commit bdc0446d7a0fe3b6d344d92fbe21fde0ce1f014d
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Thu Oct 23 13:00:27 2014 +0200

    Bug fix: equalFilePath "C:\\" "C:" == False
    
    This started out as a simple refactoring of `equalFilePath`, and later turned
    out to also fix a small bug.
    
    The refactoring is: use `dropTrailingPathSeparator` instead of the custom
    function `dropTrailSlash`.
    
    A difference between these two functions is that `dropTrailingPathSeparator`
    potentially removes multiple trailing slashes, whereas `dropTrailSlash` only
    removes the last one. But since we `normalise` the FilePath first, which
    removes superfluous pathSeparators, this difference does not matter to us.
    
    Another difference is that `dropTrailingPathSeparator` does not drop slashes
    when the FilePath isDrive, but `dropTrailSlash` does:
    
    dropTrailSlash "C:\\" == "C:"
    dropTrailSlash "C:\\\\" == "C:\\"
    
    dropTrailingPathSeparator "C:\\" == "C:\\"
    dropTrailingPathSeparator "C:\\\\" == "C:\\\\"
    
    As a result, equalFilePath of drives on Windows changes slightly:
    
    Before:
    equalFilePath "C:\\" "C:" == True
    equalFilePath "C:\\\\" "C:" == False
    
    After:
    equalFilePath "C:\\" "C:" == False
    equalFilePath "C:\\\\" "C:" == False
    
    This can be considered a bug fix, since "C:\\foo" and "C:foo", and thus "C:\\"
    and "C:", are not the same thing.


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

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

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index f85e635..83be81d 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -686,11 +686,8 @@ joinPath = foldr combine ""
 equalFilePath :: FilePath -> FilePath -> Bool
 equalFilePath a b = f a == f b
     where
-        f x | isWindows = dropTrailSlash $ map toLower $ normalise x
-            | otherwise = dropTrailSlash $ normalise x
-
-        dropTrailSlash x | length x >= 2 && hasTrailingPathSeparator x = init x
-                         | otherwise = x
+        f x | isWindows = dropTrailingPathSeparator $ map toLower $ normalise x
+            | otherwise = dropTrailingPathSeparator $ normalise x
 
 
 -- | Contract a filename, based on a relative path.
diff --git a/changelog.md b/changelog.md
index 13dad0e..b62ac45 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,9 @@
   * Bug fix: on Windows, `dropTrailingPathSeparator "/"` now returns `"/"`
     unchanged, instead of the normalised `"\\"`.
 
+  * Bug fix: on Windows, `equalFilePath "C:\\" "C:"` now retuns `False`,
+    instead of `True`.
+
 ## 1.3.0.2  *Mar 2014*
 
   * Bundled with GHC 7.8.1



More information about the ghc-commits mailing list