Skip to content

Commit cb4890a

Browse files
committed
Normalize C:\\\\ to C:\ wrt #12
1 parent 31a707c commit cb4890a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

System/FilePath/Internal.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ makeRelative root path
933933
-- > Posix: normalise "./bob/fred/" == "bob/fred/"
934934
-- > Windows: normalise "c:\\file/bob\\" == "C:\\file\\bob\\"
935935
-- > Windows: normalise "c:\\" == "C:\\"
936+
-- > Windows: normalise "c:\\\\\\\\" == "C:\\"
936937
-- > Windows: normalise "C:.\\" == "C:"
937938
-- > Windows: normalise "\\\\server\\test" == "\\\\server\\test"
938939
-- > Windows: normalise "//server/test" == "\\\\server\\test"
@@ -984,9 +985,12 @@ normaliseDrive :: FILEPATH -> FILEPATH
984985
normaliseDrive bs
985986
| null bs = mempty
986987
| isPosix = pack [pathSeparator]
987-
| otherwise = if isJust $ readDriveLetter x2
988-
then map toUpper x2
989-
else x2
988+
| Just (drv, _) <- readDriveLetter x2
989+
= case unpack drv of
990+
(x:_:[]) -> pack [toUpper x, _colon]
991+
(x:_) -> pack [toUpper x, _colon, pathSeparator]
992+
_ -> P.error "impossible"
993+
| otherwise = x2
990994
where
991995
x2 = map repSlash bs
992996
repSlash x = if isPathSeparator x then pathSeparator else x

tests/filepath-tests/TestGen.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ tests =
812812
,("AFP_W.normalise (\"c:\\\\file/bob\\\\\") == (\"C:\\\\file\\\\bob\\\\\")", property $ AFP_W.normalise ("c:\\file/bob\\") == ("C:\\file\\bob\\"))
813813
,("W.normalise \"c:\\\\\" == \"C:\\\\\"", property $ W.normalise "c:\\" == "C:\\")
814814
,("AFP_W.normalise (\"c:\\\\\") == (\"C:\\\\\")", property $ AFP_W.normalise ("c:\\") == ("C:\\"))
815+
,("W.normalise \"c:\\\\\\\\\\\\\\\\\" == \"C:\\\\\"", property $ W.normalise "c:\\\\\\\\" == "C:\\")
816+
,("AFP_W.normalise (\"c:\\\\\\\\\\\\\\\\\") == (\"C:\\\\\")", property $ AFP_W.normalise ("c:\\\\\\\\") == ("C:\\"))
815817
,("W.normalise \"C:.\\\\\" == \"C:\"", property $ W.normalise "C:.\\" == "C:")
816818
,("AFP_W.normalise (\"C:.\\\\\") == (\"C:\")", property $ AFP_W.normalise ("C:.\\") == ("C:"))
817819
,("W.normalise \"\\\\\\\\server\\\\test\" == \"\\\\\\\\server\\\\test\"", property $ W.normalise "\\\\server\\test" == "\\\\server\\test")

0 commit comments

Comments
 (0)