Cleanup escaping logic
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
module Mrsk::Utils
|
||||
extend self
|
||||
|
||||
# Return a list of shell arguments using the same named argument against the passed attributes (hash or array).
|
||||
# Return a list of escaped shell arguments using the same named argument against the passed attributes (hash or array).
|
||||
def argumentize(argument, attributes, redacted: false)
|
||||
Array(attributes).flat_map do |k, v|
|
||||
if v.present?
|
||||
[ argument, redacted ? redact("#{k}=#{escape_bash_string v.to_s}") : "#{k}=#{escape_bash_string v.to_s}" ]
|
||||
Array(attributes).flat_map do |key, value|
|
||||
if value.present?
|
||||
escaped_pair = [ key, value.to_s.dump.gsub(/`/, '\\\\`') ].join("=")
|
||||
[ argument, redacted ? redact(escaped_pair) : escaped_pair ]
|
||||
else
|
||||
[ argument, k ]
|
||||
[ argument, key ]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,8 +27,4 @@ module Mrsk::Utils
|
||||
def redact(arg) # Used in execute_command to hide redact() args a user passes in
|
||||
arg.to_s.extend(SSHKit::Redaction) # to_s due to our inability to extend Integer, etc
|
||||
end
|
||||
|
||||
def escape_bash_string(string)
|
||||
string.dump.gsub(/`/, '\\\\`')
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user