diff options
author | Joey Hess <joey@kitenet.net> | 2011-02-25 01:13:01 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-02-25 01:13:01 -0400 |
commit | 836e71297b8e3b5bd6f89f7eb1198f59af985b0b (patch) | |
tree | 835db9db776b23552736422baf9794eb6a3ac5e5 /Utility.hs | |
parent | e61b47bc8a51447f9fbde6463e09d4beef8d5a7f (diff) |
Support filenames that start with a dash; when such a file is passed to a utility it will be escaped to avoid it being interpreted as an option.
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Utility.hs b/Utility.hs index 89e129181..6a90e3cd5 100644 --- a/Utility.hs +++ b/Utility.hs @@ -15,6 +15,7 @@ module Utility ( boolSystem, shellEscape, shellUnEscape, + utilityEscape, unsetFileMode, readMaybe, safeWriteFile, @@ -179,6 +180,13 @@ shellUnEscape s = word:(shellUnEscape rest) | c == q = findword w cs | otherwise = inquote q (w++[c]) cs +{- Ensures that a filename is safe to pass to a utility program. In particular + - since utilities tend to interpret things starting with a dash as + - an option, relative filenames starting with a dash are escaped. -} +utilityEscape :: FilePath -> FilePath +utilityEscape ('-':s) = "./-" ++ s +utilityEscape s = s + {- For quickcheck. -} prop_idempotent_shellEscape :: String -> Bool prop_idempotent_shellEscape s = [s] == (shellUnEscape $ shellEscape s) |