[commit: packages/filepath] master: Bug fix: isValid "\\\\?\\D:file" == False (d6613d7)

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


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

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

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

commit d6613d73cf6da7c93db9739a8324f8f585ffbab6
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Tue Oct 28 19:55:42 2014 +0100

    Bug fix: isValid "\\\\?\\D:file" == False
    
    From http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx:
    
    * "A UNC name of any format [is never relative]."
    
    * "You cannot use the "\\?\" prefix with a relative path."


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

d6613d73cf6da7c93db9739a8324f8f585ffbab6
 System/FilePath/Internal.hs | 7 ++++++-
 changelog.md                | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index fedb014..e3fa7cb 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -800,13 +800,15 @@ badElements = ["CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5
 -- > Windows: isValid "c:\\nul\\file" == False
 -- > Windows: isValid "\\\\" == False
 -- > Windows: isValid "\\\\\\foo" == False
+-- > Windows: isValid "\\\\?\\D:file" == False
 isValid :: FilePath -> Bool
 isValid "" = False
 isValid _ | isPosix = True
 isValid path =
         not (any (`elem` badCharacters) x2) &&
         not (any f $ splitDirectories x2) &&
-        not (length x1 >= 2 && all isPathSeparator x1)
+        not (length x1 >= 2 && all isPathSeparator x1) &&
+        not (isJust (readDriveUNC x1) && not (hasTrailingPathSeparator x1))
     where
         (x1,x2) = splitDrive path
         f x = map toUpper (dropExtensions x) `elem` badElements
@@ -825,11 +827,14 @@ isValid path =
 -- > Windows: makeValid "c:\\test/prn.txt" == "c:\\test/prn_.txt"
 -- > Windows: makeValid "c:\\nul\\file" == "c:\\nul_\\file"
 -- > Windows: makeValid "\\\\\\foo" == "\\\\drive"
+-- > Windows: makeValid "\\\\?\\D:file" == "\\\\?\\D:\\file"
 makeValid :: FilePath -> FilePath
 makeValid "" = "_"
 makeValid path
         | isPosix = path
         | length drv >= 2 && all isPathSeparator drv = take 2 drv ++ "drive"
+        | isJust (readDriveUNC drv) && not (hasTrailingPathSeparator drv) =
+            makeValid (drv ++ [pathSeparator] ++ pth)
         | otherwise = joinDrive drv $ validElements $ validChars pth
     where
         (drv,pth) = splitDrive path
diff --git a/changelog.md b/changelog.md
index f46153f..ec5f0c0 100644
--- a/changelog.md
+++ b/changelog.md
@@ -24,6 +24,9 @@
   * Bug fix: on Windows, `isValid "\\\\\\foo"` now returns `False`, instead
     of `True`.
 
+  * Bug fix: on Windows, `isValid "\\\\?\\D:file"` now returns `False`,
+    instead of `True`.
+
   * Bug fix: on Windows, `normalise "\\"` now retuns `"\\"` unchanged,
     instead of `"\\\\"`.
 



More information about the ghc-commits mailing list