Browse Source

minor #5522 Token - add handling json_encode crash (keradus)

This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

Token - add handling json_encode crash

#5519 will crash without it, as we would be returning false (indicating json_encode error) instead of string

Commits
-------

d0cf53522 Token - add handling json_encode crash
Dariusz Ruminski 4 years ago
parent
commit
a2aee2f23f
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/Tokenizer/Token.php

+ 13 - 1
src/Tokenizer/Token.php

@@ -598,7 +598,19 @@ class Token
             $options = Utils::calculateBitmask($options);
         }
 
-        return json_encode($this->toArray(), $options);
+        $jsonResult = json_encode($this->toArray(), $options);
+
+        if (JSON_ERROR_NONE !== json_last_error()) {
+            $jsonResult = json_encode(
+                [
+                    'errorDescription' => 'Can not encode Tokens to JSON.',
+                    'rawErrorMessage' => json_last_error_msg(),
+                ],
+                $options
+            );
+        }
+
+        return $jsonResult;
     }
 
     /**