diff options
author | zimbatm <zimbatm@zimbatm.com> | 2016-06-19 23:27:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-19 23:27:52 +0100 |
commit | b0f8416c5c0e5345897832ae0cce139ed85c7fdb (patch) | |
tree | c34d9ef7febb4c1a6df6f179130506219e5e2d81 /lib | |
parent | 53f421c0c4b4916426c369bfb996422209e6ebf7 (diff) | |
parent | 28fa4a2f03e2232d95dec9dc2b8ef40857d725db (diff) | |
download | nixpkgs-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.nix | 11 |
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 ( |