@@ -20,6 +20,8 @@ module Obelisk.CliApp.Process
2020 , callProcess
2121 , callCommand
2222 , reconstructCommand
23+ , shellQuoteAndEscapeDouble
24+ , shellQuoteAndEscapeSingle
2325 ) where
2426
2527import Control.Monad ((<=<), join, void)
@@ -181,5 +183,10 @@ reconstructCommand :: Process.CmdSpec -> Text
181183reconstructCommand (Process.ShellCommand str) = T.pack str
182184reconstructCommand (Process.RawCommand c as) = processToShellString c as
183185 where
184− processToShellString cmd args = T.unwords $ map quoteAndEscape (cmd : args)
185− quoteAndEscape x = "'" <> T.replace "'" "'\''" (T.pack x) <> "'"
186+ processToShellString cmd args = T.unwords $ map (shellQuoteAndEscapeSingle . T.pack) (cmd : args)
187+
188+shellQuoteAndEscapeSingle :: Text -> Text
189+shellQuoteAndEscapeSingle x = "'" <> T.replace "'" "'\''" x <> "'"
190+
191+shellQuoteAndEscapeDouble :: Text -> Text
192+shellQuoteAndEscapeDouble x = "\"" <> T.replace "\"" "\\\"" x <> "\""