Skip to content

Commit 6ecece3

Browse files
authored
Check content string (#1679)
* Stricter check * Add null test
1 parent 185ca67 commit 6ecece3

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/LaravelDebugbar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ protected function isJsonRequest(Request $request, Response $response)
905905

906906
// Check if content looks like JSON without actually validating
907907
$content = $response->getContent();
908-
if ($content && in_array($content[0], ['{', '['], true)) {
908+
if (is_string($content) && strlen($content) > 0 && in_array($content[0], ['{', '['], true)) {
909909
return true;
910910
}
911911

tests/DebugbarTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public function testItInjectsOnEmptyResponse()
4747
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
4848
}
4949

50+
public function testItInjectsOnNullyResponse()
51+
{
52+
$crawler = $this->call('GET', 'web/null');
53+
54+
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
55+
$this->assertEquals(200, $crawler->getStatusCode());
56+
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
57+
}
58+
5059
public function testItInjectsOnHtml()
5160
{
5261
$crawler = $this->call('GET', 'web/html');

tests/TestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ protected function addWebRoutes(Router $router)
6666
return '';
6767
});
6868

69+
$router->get('web/null', function () {
70+
return null;
71+
});
72+
6973
$router->get('web/html', function () {
7074
return '<html><head></head><body>Pong</body></html>';
7175
});

0 commit comments

Comments
 (0)