Created
July 8, 2014 15:35
-
-
Save bholzer/9161ab4736abf8591134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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