Module: Hookit::Helper::Shell

Defined in:
lib/hookit/helper/shell.rb

Instance Method Summary collapse

Instance Method Details

#escape_shell_string(str) ⇒ Object

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



21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



5
6
7
8
9
10
# 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