From 0aa2683a1a7a405a9345e32bbeacdd6bbc1b670a Mon Sep 17 00:00:00 2001 From: Giorgio Balduzzi Date: Sat, 17 Sep 2016 16:07:26 +0000 Subject: [PATCH 1/3] Added the proper message in DomainException for all JSON error types provided by PHP --- src/JWT.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/JWT.php b/src/JWT.php index 6d30e941..ee3ac8c1 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -86,7 +86,7 @@ public static function decode($jwt, $key, $allowed_algs = array()) throw new UnexpectedValueException('Invalid claims encoding'); } $sig = static::urlsafeB64Decode($cryptob64); - + if (empty($header->alg)) { throw new UnexpectedValueException('Empty algorithm'); } @@ -343,8 +343,13 @@ private static function handleJsonError($errno) { $messages = array( JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', + JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON' + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters', //PHP >= 5.3.3 + JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', //PHP >= 5.5.0 + JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', //PHP >= 5.5.0 + JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given' //PHP >= 5.5.0 ); throw new DomainException( isset($messages[$errno]) From 3944bb9044c92714f295e98a3920ec1dd8440dc7 Mon Sep 17 00:00:00 2001 From: Giorgio Balduzzi Date: Sat, 17 Sep 2016 17:26:20 +0000 Subject: [PATCH 2/3] Deleted all PHP < 5.5 JSON error codes to keep compatibility --- src/JWT.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/JWT.php b/src/JWT.php index ee3ac8c1..de7e7c78 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -339,7 +339,7 @@ public static function urlsafeB64Encode($input) * * @return void */ - private static function handleJsonError($errno) + private static function ($errno) { $messages = array( JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', @@ -347,9 +347,6 @@ private static function handleJsonError($errno) JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters', //PHP >= 5.3.3 - JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', //PHP >= 5.5.0 - JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', //PHP >= 5.5.0 - JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given' //PHP >= 5.5.0 ); throw new DomainException( isset($messages[$errno]) From 705ea837fd4988724c9509ca49b74bb394eabc3f Mon Sep 17 00:00:00 2001 From: Giorgio Balduzzi Date: Sat, 17 Sep 2016 17:37:46 +0000 Subject: [PATCH 3/3] Fix typo --- src/JWT.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JWT.php b/src/JWT.php index de7e7c78..81b5f7b1 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -339,14 +339,14 @@ public static function urlsafeB64Encode($input) * * @return void */ - private static function ($errno) + private static function handleJsonError($errno) { $messages = array( JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters', //PHP >= 5.3.3 + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3 ); throw new DomainException( isset($messages[$errno])