Merge pull request #173 from Viximo/feature/escape-env

Quote and escape environment variables in upstart templates
This commit is contained in:
David Dollar
2012-06-07 19:43:20 -07:00
3 changed files with 22 additions and 1 deletions
+15
View File
@@ -48,4 +48,19 @@ private ######################################################################
end
end
# Quote a string to be used on the command line. Backslashes are escapde to \\ and quotes
# escaped to \"
#
# str - string to be quoted
#
# Examples
#
# shell_quote("FB|123\"\\1")
# # => "\"FB|123\"\\"\\\\1\""
#
# Returns the the escaped string surrounded by quotes
def shell_quote(str)
"\"#{str.gsub(/\\/){ '\\\\' }.gsub(/["]/){ "\\\"" }}\""
end
end