From ccba4e0226a67bee6a07308d812aacbbec19e6d1 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Fri, 26 Apr 2013 09:24:21 +0100 Subject: [PATCH 1/2] Revert "Force object-form when encoding json for sending as POST body" This reverts commit 85c2994e70428f4957858d0c934496e40f3bbc09. This change breaks issue creation. An array of labels in the parameters to api('issue')->create() 'labels'=>array('label1','label2) should be encoded as: "labels":{"label1","label2"} but with JSON_FORCE_OBJECT it is encoded as "labels":{"0":"label1","1":"label2"} which fails validation and results in 422 Unprocessable Entity. --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..8b84fc3ec47 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -168,7 +168,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) { - $request->setContent(json_encode($parameters, JSON_FORCE_OBJECT)); + $request->setContent(json_encode($parameters)); } $hasListeners = 0 < count($this->listeners); From ab724636583ad8765fb8ee61279e87ca60314b90 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Fri, 26 Apr 2013 09:42:22 +0100 Subject: [PATCH 2/2] Update JSON_FORCE_OBJECT usage based on whether params are empty --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 8b84fc3ec47..fe5fe1cd75e 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -168,7 +168,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) { - $request->setContent(json_encode($parameters)); + $request->setContent(json_encode($parameters, empty($parameters)? JSON_FORCE_OBJECT : 0)); } $hasListeners = 0 < count($this->listeners);