File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,10 @@ public static function decode(
111
111
if (null === ($ payload = static ::jsonDecode ($ payloadRaw ))) {
112
112
throw new UnexpectedValueException ('Invalid claims encoding ' );
113
113
}
114
+ if (is_array ($ payload )) {
115
+ // prevent PHP Fatal Error in edge-cases when payload is empty array
116
+ $ payload = (object ) $ payload ;
117
+ }
114
118
if (!$ payload instanceof stdClass) {
115
119
throw new UnexpectedValueException ('Payload must be a JSON object ' );
116
120
}
@@ -355,7 +359,7 @@ public static function jsonDecode(string $input)
355
359
public static function jsonEncode (array $ input ): string
356
360
{
357
361
if (PHP_VERSION_ID >= 50400 ) {
358
- $ json = \json_encode ($ input , \JSON_UNESCAPED_SLASHES |\ JSON_FORCE_OBJECT );
362
+ $ json = \json_encode ($ input , \JSON_UNESCAPED_SLASHES );
359
363
} else {
360
364
// PHP 5.3 only
361
365
$ json = \json_encode ($ input );
Original file line number Diff line number Diff line change @@ -330,6 +330,15 @@ public function testDecodesEmptyArrayAsObject()
330
330
$ this ->assertEquals ((object ) $ payload , $ decoded );
331
331
}
332
332
333
+ public function testDecodesArraysInJWTAsArray ()
334
+ {
335
+ $ key = 'yma6Hq4XQegCVND8ef23OYgxSrC3IKqk ' ;
336
+ $ payload = ['foo ' => [1 ,2 ,3 ]];
337
+ $ jwt = JWT ::encode ($ payload , $ key , 'HS256 ' );
338
+ $ decoded = JWT ::decode ($ jwt , new Key ($ key , 'HS256 ' ));
339
+ $ this ->assertEquals ($ payload ['foo ' ], $ decoded ->foo );
340
+ }
341
+
333
342
/**
334
343
* @runInSeparateProcess
335
344
* @dataProvider provideEncodeDecode
You can’t perform that action at this time.
0 commit comments