Skip to content

Commit

Permalink
Merge pull request #53 from sandfox-im/master
Browse files Browse the repository at this point in the history
Decode failure detection is incorrect in PestJSON
  • Loading branch information
djsipe committed May 9, 2014
2 parents 31e1b7a + a8fc5f3 commit 6a8e9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor/
.idea
.idea
*.iml
*.ipr
16 changes: 15 additions & 1 deletion PestJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a8e9f4

Please sign in to comment.