Skip to content

Instantly share code, notes, and snippets.

@bholzer
Created July 8, 2014 15:35
Show Gist options
  • Save bholzer/9161ab4736abf8591134 to your computer and use it in GitHub Desktop.
Save bholzer/9161ab4736abf8591134 to your computer and use it in GitHub Desktop.
def escape_response
escape = lambda do |unescaped_response|
unescaped_response.each do |value|
if value.is_a?(String)
value = ERB::Util.h(value)
elsif [Array, Hash].any?{|klass| value.is_a?(klass) }
value = escape.call(value)
end
end
end
if response.content_type == 'application/json'
response_body = JSON.parse(response.body)
escaped_hash = escape.call(response_body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment