Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix a bug that caused request: didLoad: to be called with the raw res…

…ponse instead of a string when the response does not represent a valid JSON object.

Summary:
If the response is not a JSON object, convert the actual response to a string instead of using the NSData object.
This will break clients that depend on the current behavior. If you need access to the raw response, use request: diReceiveResponse: instead.

Test Plan: Test with stream.publish requests

Reviewers: jacl, dgibson, yariv, caabernathy

Reviewed By: jacl

CC: leon

Differential Revision: https://phabricator.fb.com/D427844

Task ID: 842334
  • Loading branch information...
commit 81c29542ce90790982659fe343ae7ac13a807323 1 parent 84e953c
@suhasjoshi suhasjoshi authored
View
13 sample/Hackbook/Hackbook/RootViewController.m
@@ -373,8 +373,9 @@ - (void)fbSessionInvalidated {
#pragma mark - FBRequestDelegate Methods
/**
- * Called when the Facebook API request has returned a response. This callback
- * gives you access to the raw response. It's called before
+ * Called when the Facebook API request has returned a response.
+ *
+ * This callback gives you access to the raw response. It's called before
* (void)request:(FBRequest *)request didLoad:(id)result,
* which is passed the parsed response object.
*/
@@ -384,9 +385,11 @@ - (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)respons
/**
* Called when a request returns and its response has been parsed into
- * an object. The resulting object may be a dictionary, an array, a string,
- * or a number, depending on the format of the API response. If you need access
- * to the raw response, use:
+ * an object.
+ *
+ * The resulting object may be a dictionary, an array or a string, depending
+ * on the format of the API response. If you need access to the raw response,
+ * use:
*
* (void)request:(FBRequest *)request
* didReceiveResponse:(NSURLResponse *)response
View
14 src/FBRequest.h
@@ -105,7 +105,11 @@ typedef NSUInteger FBRequestState;
- (void)requestLoading:(FBRequest *)request;
/**
- * Called when the server responds and begins to send back data.
+ * Called when the Facebook API request has returned a response.
+ *
+ * This callback gives you access to the raw response. It's called before
+ * (void)request:(FBRequest *)request didLoad:(id)result,
+ * which is passed the parsed response object.
*/
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response;
@@ -118,8 +122,12 @@ typedef NSUInteger FBRequestState;
* Called when a request returns and its response has been parsed into
* an object.
*
- * The resulting object may be a dictionary, an array, a string, or a number,
- * depending on thee format of the API response.
+ * The resulting object may be a dictionary, an array or a string, depending
+ * on the format of the API response. If you need access to the raw response,
+ * use:
+ *
+ * (void)request:(FBRequest *)request
+ * didReceiveResponse:(NSURLResponse *)response
*/
- (void)request:(FBRequest *)request didLoad:(id)result;
View
13 src/FBRequest.m
@@ -189,7 +189,6 @@ - (id)parseJsonResponse:(NSData *)data error:(NSError **)error {
NSString* responseString = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding]
autorelease];
- SBJSON *jsonParser = [[SBJSON new] autorelease];
if ([responseString isEqualToString:@"true"]) {
return [NSDictionary dictionaryWithObject:@"true" forKey:@"result"];
} else if ([responseString isEqualToString:@"false"]) {
@@ -203,9 +202,15 @@ - (id)parseJsonResponse:(NSData *)data error:(NSError **)error {
}
+ SBJSON *jsonParser = [[SBJSON alloc] init];
id result = [jsonParser objectWithString:responseString];
-
- if (![result isKindOfClass:[NSArray class]]) {
+ [jsonParser release];
+
+ if (result == nil) {
+ return responseString;
+ }
+
+ if ([result isKindOfClass:[NSDictionary class]]) {
if ([result objectForKey:@"error"] != nil) {
if (error != nil) {
*error = [self formError:kGeneralErrorCode
@@ -272,7 +277,7 @@ - (void)handleResponseData:(NSData *)data {
[self failWithError:error];
} else if ([_delegate respondsToSelector:
@selector(request:didLoad:)]) {
- [_delegate request:self didLoad:(result == nil ? data : result)];
+ [_delegate request:self didLoad:result];
}
}

0 comments on commit 81c2954

Please sign in to comment.
Something went wrong with that request. Please try again.