lib shell.escape: escape the empty string as ''

This commit is contained in:
tv 2017-09-19 20:42:27 +02:00
parent 3416a45b54
commit 8179f87e5a
1 changed files with 7 additions and 4 deletions

View File

@ -7,10 +7,13 @@ rec {
let let
isSafeChar = testString "[-+./0-9:=A-Z_a-z]"; isSafeChar = testString "[-+./0-9:=A-Z_a-z]";
in in
stringAsChars (c: x:
if isSafeChar c then c if x == "" then "''"
else if c == "\n" then "'\n'" else stringAsChars (c:
else "\\${c}"); if isSafeChar c then c
else if c == "\n" then "'\n'"
else "\\${c}"
) x;
# #
# shell script generators # shell script generators