Browse files

Mogli client is more resilient to Facebook's JSON

Facebook APIs return numbers, "true" and "false" as valid JSON, even though the
JSON RFC defines JSON objects as starting with "[" or "{". As such, when the
client is looking at parsed JSON returned from a Facebook API call, it will
crash on numbers and booleans because they don't respond to the :has_keys?
  • Loading branch information...
1 parent cf14773 commit b4fc71930b4c30e64043bd9d81d52d410dfeed5b @derwiki committed with Adam Derewecki Apr 16, 2012
Showing with 3 additions and 0 deletions.
  1. +3 −0 lib/mogli/client.rb
@@ -161,10 +161,13 @@ def extract_hash_or_array(hash_or_array,klass)
return nil if hash_or_array == false
return hash_or_array if hash_or_array.nil? or hash_or_array.kind_of?(Array)
return extract_fetching_array(hash_or_array,klass) if is_fetching_array?(hash_or_array)
+ # Facebook doesn't return numbers or booleans in an object or list
+ # container; this will catch the number, "true" and "false" response case
return hash_or_array
def is_fetching_array?(hash)
+ return false unless hash.respond_to? :has_key
hash.has_key?("data") and hash["data"].instance_of?(Array)

0 comments on commit b4fc719

Please sign in to comment.