Skip to content

Commit

Permalink
Check content string (#1679)
Browse files Browse the repository at this point in the history
* Stricter check

* Add null test
  • Loading branch information
barryvdh authored Sep 24, 2024
1 parent 185ca67 commit 6ecece3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/DebugbarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ protected function addWebRoutes(Router $router)
return '';
});

$router->get('web/null', function () {
return null;
});

$router->get('web/html', function () {
return '<html><head></head><body>Pong</body></html>';
});
Expand Down

0 comments on commit 6ecece3

Please sign in to comment.