From d3cb65c0874cf76a9a4ea6524fd515671b114b18 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Fri, 30 Nov 2012 14:40:53 -0800 Subject: [PATCH] [Issue #651] Adding workaround for Rails behavior of returning a single space in head :ok responses, which is interpreted as invalid input by NSJSONSerialization Signed-off-by: Mattt Thompson --- AFNetworking/AFJSONRequestOperation.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 78f3bb2..5401cbf 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -64,7 +64,9 @@ static dispatch_queue_t json_request_operation_processing_queue() { if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) { NSError *error = nil; - if ([self.responseData length] == 0) { + // Workaround for behavior of Rails to return a single space for `head :ok` (a workaround for a bug in Safari), which is not interpreted as valid input by NSJSONSerialization. + // See https://github.com/rails/rails/issues/1742 + if ([self.responseData length] == 0 || [self.responseString isEqualToString:@" "]) { self.responseJSON = nil; } else { // Workaround for a bug in NSJSONSerialization when Unicode character escape codes are used instead of the actual character