Skip to content

Commit 185ca67

Browse files
authored
Bugfix: Prevent ErrorException on empty responses (barryvdh#1677)
1 parent 16a13cc commit 185ca67

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 !== false && in_array($content[0], ['{', '['], true)) {
908+
if ($content && 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
@@ -38,6 +38,15 @@ public function testItInjectsOnPlainText()
3838
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
3939
}
4040

41+
public function testItInjectsOnEmptyResponse()
42+
{
43+
$crawler = $this->call('GET', 'web/empty');
44+
45+
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
46+
$this->assertEquals(200, $crawler->getStatusCode());
47+
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
48+
}
49+
4150
public function testItInjectsOnHtml()
4251
{
4352
$crawler = $this->call('GET', 'web/html');

tests/TestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function addWebRoutes(Router $router)
6262
return 'PONG';
6363
});
6464

65+
$router->get('web/empty', function () {
66+
return '';
67+
});
68+
6569
$router->get('web/html', function () {
6670
return '<html><head></head><body>Pong</body></html>';
6771
});

0 commit comments

Comments
 (0)