]> git.e2factory.org Git - e2factory.git/commitdiff
Introduce e2lib.shquote() to quote strings that are passed to a shell
authorTobias Ulmer <tu@emlix.com>
Fri, 29 Jun 2012 19:39:13 +0000 (21:39 +0200)
committerTobias Ulmer <tu@emlix.com>
Fri, 29 Jun 2012 19:39:13 +0000 (21:39 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index 68b575bf8818ef81c43b4d3801f7ca7bc4b082f6..cd91d3601779d434d27080cd747c4d53f75205e8 100644 (file)
@@ -681,6 +681,16 @@ function chomp(str, chr)
   end
 end
 
+--- quotes a string so it can be safely passed to a shell
+-- @param str string to quote
+-- @return quoted string
+function shquote(str)
+  assert(type(str) == "string")
+  e2lib.logf(4, "e2lib.shquote(%s)", str)
+  str = string.gsub(str, "'", "'\"'\"'")
+  return "'"..str.."'"
+end
+
 -- determines the type of an archive
 -- say "z" for gzip, "j" for bzip2, "" for tar archive
 -- nil is returned for unknown data