[commit: packages/filepath] master: Bug fix: normalise "C:.\\" == "C:" (00e784d)
git at git.haskell.org
git at git.haskell.org
Thu Mar 19 11:35:31 UTC 2015
Repository : ssh://git@git.haskell.org/filepath
On branch : master
Link : http://git.haskell.org/packages/filepath.git/commitdiff/00e784d32cbe28405a73c3cc404a1ac45c045a08
>---------------------------------------------------------------
commit 00e784d32cbe28405a73c3cc404a1ac45c045a08
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date: Mon Oct 27 19:47:44 2014 +0100
Bug fix: normalise "C:.\\" == "C:"
Another other option would be `normalise "C:.\\" == "C:.\\"`, but this is
nicer since we already have:
> normalise "C:.\\foo"
"C:foo"
>---------------------------------------------------------------
00e784d32cbe28405a73c3cc404a1ac45c045a08
System/FilePath/Internal.hs | 7 +++++--
changelog.md | 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index 709751c..c3f2721 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -731,6 +731,7 @@ makeRelative root path
-- > Posix: normalise "./bob/fred/" == "bob/fred/"
-- > Windows: normalise "c:\\file/bob\\" == "C:\\file\\bob\\"
-- > Windows: normalise "c:\\" == "C:\\"
+-- > Windows: normalise "C:.\\" == "C:"
-- > Windows: normalise "\\\\server\\test" == "\\\\server\\test"
-- > Windows: normalise "//server/test" == "\\\\server\\test"
-- > Windows: normalise "c:/file" == "C:\\file"
@@ -755,6 +756,7 @@ normalise path = result ++ [pathSeparator | addPathSeparator]
addPathSeparator = isDirPath pth
&& not (hasTrailingPathSeparator result)
+ && not (isRelativeDrive drv)
isDirPath xs = hasTrailingPathSeparator xs
|| not (null xs) && last xs == '.' && hasTrailingPathSeparator (init xs)
@@ -868,7 +870,8 @@ makeValid path = joinDrive drv $ validElements $ validChars pth
--
-- * "You cannot use the "\\?\" prefix with a relative path."
isRelative :: FilePath -> Bool
-isRelative = isRelativeDrive . takeDrive
+isRelative x = null drive || isRelativeDrive drive
+ where drive = takeDrive x
{- c:foo -}
@@ -876,7 +879,7 @@ isRelative = isRelativeDrive . takeDrive
-- backslash after the colon, it is interpreted as a relative path to the
-- current directory on the drive with the specified letter."
isRelativeDrive :: String -> Bool
-isRelativeDrive x = null x ||
+isRelativeDrive x =
maybe False (not . hasTrailingPathSeparator . fst) (readDriveLetter x)
diff --git a/changelog.md b/changelog.md
index 6e5f2df..f46153f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -27,6 +27,9 @@
* Bug fix: on Windows, `normalise "\\"` now retuns `"\\"` unchanged,
instead of `"\\\\"`.
+ * Bug fix: on Windows, `normalise "C:.\\"` now retuns `"C:"`, instead of
+ `"C:\\"`.
+
* Bug fix: on Windows, `normalise "//server/test"` now retuns
`"\\\\server\\test"`, instead of `"//server/test"` unchanged.
More information about the ghc-commits
mailing list