Skip to content

Commit c394803

Browse files
committed
Fix regression of splitFileName on '//?/A:'
1 parent 399df96 commit c394803

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

System/FilePath/Internal.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,26 @@ splitFileName_ fp
645645
-- or UNC location "\\?\UNC\foo", where path separator is a part of the drive name.
646646
-- We can test this by trying dropDrive and falling back to splitDrive.
647647
| isWindows
648-
, Just (s1, _s2, bs') <- uncons2 dirSlash
649-
, isPathSeparator s1
650-
-- If bs' is empty, then s2 as the last character of dirSlash must be a path separator,
651-
-- so we are in the middle of shared drive.
652-
-- Otherwise, since s1 is a path separator, we might be in the middle of UNC path.
653-
, null bs' || maybe False isIncompleteUNC (readDriveUNC dirSlash)
654-
= (fp, mempty)
648+
= case uncons2 dirSlash of
649+
Just (s1, s2, bs')
650+
| isPathSeparator s1
651+
-- If bs' is empty, then s2 as the last character of dirSlash must be a path separator,
652+
-- so we are in the middle of shared drive.
653+
-- Otherwise, since s1 is a path separator, we might be in the middle of UNC path.
654+
, null bs' || maybe False isIncompleteUNC (readDriveUNC dirSlash)
655+
-> (fp, mempty)
656+
-- This handles inputs like "//?/A:" and "//?/A:foo"
657+
| isPathSeparator s1
658+
, isPathSeparator s2
659+
, Just (s3, s4, bs'') <- uncons2 bs'
660+
, s3 == _question
661+
, isPathSeparator s4
662+
, null bs''
663+
, Just (drive, rest) <- readDriveLetter file
664+
-> (dirSlash <> drive, rest)
665+
_ -> (dirSlash, file)
655666
| otherwise
656-
= (dirSlash, file)
667+
= (dirSlash, file)
657668
where
658669
(dirSlash, file) = breakEnd isPathSeparator fp
659670

0 commit comments

Comments
 (0)