on master help sign in
added posix shell escape lib
commit5224b21179284beec16a3da1984cbdad90b74df1 authorOwen Shepherd <414owen@gmail.com> dateWed 18 Dec 2019, 14:53 (7 years ago) parentfc01e72
7 files changed+9−3
lib/cliapp/obelisk-cliapp.cabal+1 lib/cliapp/src/Obelisk/CliApp/Process.hs+2−2 lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command.hs+2−1 result-2+1 result-3+1 result-4+1
lib/cliapp/obelisk-cliapp.cabal+1
@@ -16,6 +16,7 @@ library
1616 , logging-effect
1717 , monad-loops
1818 , mtl
19+ , posix-escape
1920 , process
2021 , terminal-size
2122 , text
lib/cliapp/src/Obelisk/CliApp/Process.hs+2−2
@@ -40,6 +40,7 @@ import System.IO (Handle)
4040import System.IO.Streams (InputStream, handleToInputStream)
4141import qualified System.IO.Streams as Streams
4242import System.IO.Streams.Concurrent (concurrentMerge)
43+import System.Posix.Escape (escape)
4344import System.Process (CreateProcess, ProcessHandle, StdStream (CreatePipe), cmdspec, std_err, std_out,
4445 waitForProcess)
4546import qualified System.Process as Process
@@ -182,5 +183,4 @@ reconstructCommand :: Process.CmdSpec -> Text
182183reconstructCommand (Process.ShellCommand str) = T.pack str
183184reconstructCommand (Process.RawCommand c as) = processToShellString c as
184185 where
185− processToShellString cmd args = T.unwords $ map quoteAndEscape (cmd : args)
186− quoteAndEscape x = "'" <> T.replace "'" "'\''" (T.pack x) <> "'"
186+ processToShellString cmd args = T.pack $ unwords $ map escape (cmd : args)
lib/command/obelisk-command.cabal+1
@@ -39,6 +39,7 @@ library
3939 , optparse-applicative
4040 , placeholders
4141 , process
42+ , posix-escape
4243 , temporary
4344 , terminal-size
4445 , text
lib/command/src/Obelisk/Command.hs+2−1
@@ -26,6 +26,7 @@ import System.Environment
2626import System.FilePath
2727import qualified System.Info
2828import System.IO (hIsTerminalDevice, stdout)
29+import System.Posix.Escape (escapeMany)
2930import System.Posix.Process (executeFile)
3031
3132import Obelisk.App
@@ -105,7 +106,7 @@ data ObInternal
105106
106107inNixShell' :: MonadObelisk m => StaticPtr (ObeliskT IO ()) -> m ()
107108inNixShell' p = withProjectRoot "." $ \root -> do
108− cmd <- liftIO $ unwords <$> mkCmd -- TODO: shell escape instead of unwords
109+ cmd <- liftIO $ escapeMany <$> mkCmd
109110 projectShell root True "ghc" (Just cmd)
110111 where
111112 mkCmd = do
result-2new file+1
@@ -0,0 +1 @@
1+/nix/store/dm824gcp9v1lpym0fvj9waric653954h-selftest
result-3new file+1
@@ -0,0 +1 @@
1+/nix/store/4d5y7m7j4ljgza99hwfnrwxaa5ll8gik-obelisk-shell
result-4new file+1
@@ -0,0 +1 @@
1+/nix/store/9xix8yxpsasrg5ph7xgm7wyi8sykfhaf-skeleton