File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -355,7 +355,7 @@ public static function jsonDecode(string $input)
355355 public static function jsonEncode (array $ input ): string
356356 {
357357 if (PHP_VERSION_ID >= 50400 ) {
358- $ json = \json_encode ($ input , \JSON_UNESCAPED_SLASHES );
358+ $ json = \json_encode ($ input , \JSON_UNESCAPED_SLASHES |\ JSON_FORCE_OBJECT );
359359 } else {
360360 // PHP 5.3 only
361361 $ json = \json_encode ($ input );
Original file line number Diff line number Diff line change @@ -321,6 +321,15 @@ public function testRSEncodeDecodeWithPassphrase()
321321 $ this ->assertEquals ($ decoded , $ expected );
322322 }
323323
324+ public function testDecodesEmptyArrayAsObject ()
325+ {
326+ $ key = 'yma6Hq4XQegCVND8ef23OYgxSrC3IKqk ' ;
327+ $ payload = [];
328+ $ jwt = JWT ::encode ($ payload , $ key , 'HS256 ' );
329+ $ decoded = JWT ::decode ($ jwt , new Key ($ key , 'HS256 ' ));
330+ $ this ->assertEquals ((object ) $ payload , $ decoded );
331+ }
332+
324333 /**
325334 * @runInSeparateProcess
326335 * @dataProvider provideEncodeDecode
You can’t perform that action at this time.
0 commit comments