From b5a495095ff9ed079e0963f6136a5b27dcd97ac1 Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Wed, 7 May 2014 17:43:53 +0400 Subject: [PATCH 1/2] Ignore IntelliJ Idea project files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ccef056..c513ef1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor/ -.idea \ No newline at end of file +.idea +*.iml +*.ipr From a8fc5f30955d177259bfe3cf9eaf08e6cd9e9bef Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Wed, 7 May 2014 17:46:09 +0400 Subject: [PATCH 2/2] Fix json decode failure detection --- PestJSON.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/PestJSON.php b/PestJSON.php index e41c8de..b60e0a1 100644 --- a/PestJSON.php +++ b/PestJSON.php @@ -93,7 +93,7 @@ public function jsonDecode($data, $asArray=true) { $ret = json_decode($data, $asArray); - if ($ret === false && $this->throwJsonExceptions) { + if ($ret === null && $this->hasJsonDecodeFailed() && $this->throwJsonExceptions) { throw new Pest_Json_Decode( 'Decoding error: ' . $this->getLastJsonErrorMessage(), $this->getLastJsonErrorCode() @@ -161,6 +161,20 @@ public function getLastJsonErrorCode() return json_last_error(); } + /** + * Check if decoding failed + * @return bool + */ + private function hasJsonDecodeFailed() + { + // you cannot safely determine decode errors in PHP < 5.3 + if (!function_exists('json_last_error')) { + return false; + } + + return json_last_error() !== JSON_ERROR_NONE; + } + /** * Process body * @param string $body