lib/foreman/export/base.rb in foreman-0.46.0-java vs lib/foreman/export/base.rb in foreman-0.47.0
- old
+ new
@@ -46,6 +46,21 @@
File.open(filename, "w") do |file|
file.puts contents
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