diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs index 42283767..30ee3724 100644 --- a/System/FilePath/Internal.hs +++ b/System/FilePath/Internal.hs @@ -844,8 +844,8 @@ normaliseDrive drive = if isJust $ readDriveLetter x2 repSlash x = if isPathSeparator x then pathSeparator else x -- Information for validity functions on Windows. See [1]. -badCharacters :: [Char] -badCharacters = ":*?><|\"" +isBadCharacter :: Char -> Bool +isBadCharacter x = x >= '\0' && x <= '\31' || x `elem` ":*?><|\"" badElements :: [FilePath] badElements = @@ -871,12 +871,13 @@ badElements = -- > Windows: isValid "\\\\" == False -- > Windows: isValid "\\\\\\foo" == False -- > Windows: isValid "\\\\?\\D:file" == False +-- > Windows: isValid "foo\tbar" == False isValid :: FilePath -> Bool isValid "" = False isValid x | '\0' `elem` x = False isValid _ | isPosix = True isValid path = - not (any (`elem` badCharacters) x2) && + not (any isBadCharacter x2) && not (any f $ splitDirectories x2) && not (isJust (readDriveShare x1) && all isPathSeparator x1) && not (isJust (readDriveUNC x1) && not (hasTrailingPathSeparator x1)) @@ -912,8 +913,7 @@ makeValid path (drv,pth) = splitDrive path validChars = map f - f x | x `elem` badCharacters || x == '\0' = '_' - | otherwise = x + f x = if isBadCharacter x then '_' else x validElements x = joinPath $ map g $ splitPath x g x = h a ++ b diff --git a/tests/TestGen.hs b/tests/TestGen.hs index 7dfaffcc..c3b1acd0 100755 --- a/tests/TestGen.hs +++ b/tests/TestGen.hs @@ -384,6 +384,7 @@ tests = ,("W.isValid \"\\\\\\\\\" == False", test $ W.isValid "\\\\" == False) ,("W.isValid \"\\\\\\\\\\\\foo\" == False", test $ W.isValid "\\\\\\foo" == False) ,("W.isValid \"\\\\\\\\?\\\\D:file\" == False", test $ W.isValid "\\\\?\\D:file" == False) + ,("W.isValid \"foo\\tbar\" == False", test $ W.isValid "foo\tbar" == False) ,("P.isValid (P.makeValid x)", test $ \(QFilePath x) -> P.isValid (P.makeValid x)) ,("W.isValid (W.makeValid x)", test $ \(QFilePath x) -> W.isValid (W.makeValid x)) ,("P.isValid x ==> P.makeValid x == x", test $ \(QFilePath x) -> P.isValid x ==> P.makeValid x == x)