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

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 x == "" then "''"
else stringAsChars (c:
if isSafeChar c then c if isSafeChar c then c
else if c == "\n" then "'\n'" else if c == "\n" then "'\n'"
else "\\${c}"); else "\\${c}"
) x;
# #
# shell script generators # shell script generators