diff options
author | Joey Hess <joey@kitenet.net> | 2013-11-14 17:04:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-11-14 17:04:58 -0400 |
commit | 521ef9dfebd6a9418a5dce7d1686dbf353ddd0a0 (patch) | |
tree | afe6bb5d52e21a049f04020ae448afb81adc02a7 /Utility/Path.hs | |
parent | f4b4f327b69189d24663a7db6407c1f7a6e48fdd (diff) | |
parent | 5c6f6e4d0abb9b4856908a500611044b3b7a48e6 (diff) |
Merge branch 'master' into tasty-tests
Conflicts:
Test.hs
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r-- | Utility/Path.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs index 79e8e8089..b6214b247 100644 --- a/Utility/Path.hs +++ b/Utility/Path.hs @@ -14,6 +14,7 @@ import System.FilePath import System.Directory import Data.List import Data.Maybe +import Data.Char import Control.Applicative #ifdef mingw32_HOST_OS @@ -236,3 +237,18 @@ fileNameLengthLimit dir = do else return $ minimum [l, 255] where #endif + +{- Given a string that we'd like to use as the basis for FilePath, but that + - was provided by a third party and is not to be trusted, returns the closest + - sane FilePath. + - + - All spaces and punctuation are replaced with '_', except for '.' + - "../" will thus turn into ".._", which is safe. + -} +sanitizeFilePath :: String -> FilePath +sanitizeFilePath = map sanitize + where + sanitize c + | c == '.' = c + | isSpace c || isPunctuation c || c == '/' = '_' + | otherwise = c |