From 6ecece3edf0c900cd4eeba541c1919547688b803 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 24 Sep 2024 18:57:31 +0200 Subject: [PATCH] Check content string (#1679) * Stricter check * Add null test --- src/LaravelDebugbar.php | 2 +- tests/DebugbarTest.php | 9 +++++++++ tests/TestCase.php | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index 98d1bb7e..2345e9f8 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -905,7 +905,7 @@ protected function isJsonRequest(Request $request, Response $response) // Check if content looks like JSON without actually validating $content = $response->getContent(); - if ($content && in_array($content[0], ['{', '['], true)) { + if (is_string($content) && strlen($content) > 0 && in_array($content[0], ['{', '['], true)) { return true; } diff --git a/tests/DebugbarTest.php b/tests/DebugbarTest.php index 3a4457d7..7a9472cb 100644 --- a/tests/DebugbarTest.php +++ b/tests/DebugbarTest.php @@ -47,6 +47,15 @@ public function testItInjectsOnEmptyResponse() $this->assertNotEmpty($crawler->headers->get('phpdebugbar-id')); } + public function testItInjectsOnNullyResponse() + { + $crawler = $this->call('GET', 'web/null'); + + $this->assertTrue(Str::contains($crawler->content(), 'debugbar')); + $this->assertEquals(200, $crawler->getStatusCode()); + $this->assertNotEmpty($crawler->headers->get('phpdebugbar-id')); + } + public function testItInjectsOnHtml() { $crawler = $this->call('GET', 'web/html'); diff --git a/tests/TestCase.php b/tests/TestCase.php index 04b30b4d..567326d3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -66,6 +66,10 @@ protected function addWebRoutes(Router $router) return ''; }); + $router->get('web/null', function () { + return null; + }); + $router->get('web/html', function () { return 'Pong'; });