summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2009-05-06 16:06:41 +0000
committerMarc Weber <marco-oweber@gmx.de>2009-05-06 16:06:41 +0000
commit8cc89653796edd399cabe369bd77ffec6b2ee5e1 (patch)
treee7ecec14fbbe93dc9344de00c52a0893ab15f3fe /pkgs
parent16ca65b0c2fb4c2bf83b1e4540f1e3eef195b3e5 (diff)
downloadnixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar.gz
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar.bz2
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar.lz
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar.xz
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.tar.zst
nixpkgs-8cc89653796edd399cabe369bd77ffec6b2ee5e1.zip
enhance escapeShellArg funtion. It should be pretty correct now
svn path=/nixpkgs/trunk/; revision=15475
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/lib/strings.nix13
1 files changed, 8 insertions, 5 deletions
diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix
index 263e659f2ec..9c045e9ae53 100644
--- a/pkgs/lib/strings.nix
+++ b/pkgs/lib/strings.nix
@@ -66,11 +66,14 @@ rec {
     else [(substring 0 1 s)] ++ stringToCharacters (substring 1 (builtins.sub l 1) s);
 
     
-  # !!! this function seems broken - it doesn't escape all special
-  # characters, and in any case this should be done in a builder.
-  escapeShellArg = s:
-    let escapeChar = x: if x == "'" then "'\"'\"'" else x;
-    in "'" + concatStrings (map escapeChar (stringToCharacters s)) + "'";
+  # same as vim escape function.
+  # Each character contained in list is prefixed by "\"
+  escape = list : string :
+    lib.concatStrings (map (c: if lib.elem c list then "\\${c}" else c) (stringToCharacters string));
+
+  # still ugly slow. But more correct now
+  # [] for zsh
+  escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]");
 
     
   # !!! what is this for?