File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,9 @@ public function setData($data = [])
74
74
{
75
75
$ this ->original = $ data ;
76
76
77
+ // Ensure json_last_error() is cleared...
78
+ json_decode ('[] ' );
79
+
77
80
if ($ data instanceof Jsonable) {
78
81
$ this ->data = $ data ->toJson ($ this ->encodingOptions );
79
82
} elseif ($ data instanceof JsonSerializable) {
Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Tests \Integration \Http ;
4
4
5
+ use Illuminate \Contracts \Support \Jsonable ;
5
6
use Illuminate \Http \JsonResponse ;
6
7
use Illuminate \Support \Facades \Route ;
7
8
use Orchestra \Testbench \TestCase ;
@@ -27,4 +28,22 @@ public function jsonSerialize(): string
27
28
28
29
$ this ->get ('/response ' );
29
30
}
31
+
32
+ public function testResponseSetDataPassesWithPriorJsonErrors ()
33
+ {
34
+ $ response = new JsonResponse ();
35
+
36
+ // Trigger json_last_error() to have a non-zero value...
37
+ json_encode (['a ' => acos (2 )]);
38
+
39
+ $ response ->setData (new class implements Jsonable
40
+ {
41
+ public function toJson ($ options = 0 ): string
42
+ {
43
+ return '{} ' ;
44
+ }
45
+ });
46
+
47
+ $ this ->assertJson ($ response ->getContent ());
48
+ }
30
49
}
You can’t perform that action at this time.
0 commit comments