summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2016-06-19 23:27:52 +0100
committerGitHub <noreply@github.com>2016-06-19 23:27:52 +0100
commitb0f8416c5c0e5345897832ae0cce139ed85c7fdb (patch)
treec34d9ef7febb4c1a6df6f179130506219e5e2d81 /lib
parent53f421c0c4b4916426c369bfb996422209e6ebf7 (diff)
parent28fa4a2f03e2232d95dec9dc2b8ef40857d725db (diff)
downloadnixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar.gz
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar.bz2
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar.lz
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar.xz
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.tar.zst
nixpkgs-b0f8416c5c0e5345897832ae0cce139ed85c7fdb.zip
Merge pull request #16180 from zimbatm/shell-escaping
Escape all shell arguments uniformly
Diffstat (limited to 'lib')
-rw-r--r--lib/strings.nix11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 7109bd4ec6e..04376a5f2fb 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -209,7 +209,16 @@ rec {
        escapeShellArg "so([<>])me"
        => "so\\(\\[\\<\\>\\]\\)me"
   */
-  escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]");
+  escapeShellArg = arg:
+    lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]") (toString arg);
+
+  /* Escape all arguments to be passed to the Bourne shell.
+
+     Example:
+       escapeShellArgs ["one" "two three"]
+       => "one two\\ three"
+  */
+  escapeShellArgs = concatMapStringsSep " " escapeShellArg;
 
   /* Obsolete - use replaceStrings instead. */
   replaceChars = builtins.replaceStrings or (