module Hookit::Helper::Shell

Public Instance Methods

escape_shell_string(str) click to toggle source

strategy: 1- escape the escapes 2- escape quotes 3- escape backticks 4- escape semicolons 5- escape ampersands 6- escape pipes 7- escape dollar signs 8- escape spaces

# File lib/hookit/helper/shell.rb, line 21
def escape_shell_string(str)
  str = str.gsub(/\\/, "\\\\\\")
  str = str.gsub(/"/, "\\\"")
  str = str.gsub(/`/, "\\`")
  str = str.gsub(/;/, "\\;")
  str = str.gsub(/&/, "\\&")
  str = str.gsub(/\|/, "\\|")
  str = str.gsub(/\$/, "\\$")
  str = str.gsub(/ /, "\\ ")
  str
end
sanitize_shell_vars(vars) click to toggle source
# File lib/hookit/helper/shell.rb, line 5
def sanitize_shell_vars(vars)
  vars.inject({}) do |res, (key,value)|
    res[escape_shell_string(key.to_s)] = escape_shell_string(value.to_s)
    res
  end
end