Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ErrorException on empty responses #1677

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

stefket
Copy link
Contributor

@stefket stefket commented Sep 23, 2024

For example, the spatie/laravel-honeypot package returns an empty response if the honeypot field is filled in. In this case, the Laravel Debugbar triggers an ErrorException with the message “Uninitialized string offset 0.”

@@ -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 !== false && in_array($content[0], ['{', '['], true)) {
if ($content && in_array($content[0], ['{', '['], true)) {
Copy link
Contributor

@erikn69 erikn69 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-if ($content && in_array($content[0], ['{', '['], true)) {
+if (is_string($content) && in_array($content[0] ?? '', ['{', '['], true)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-if ($content && in_array($content[0], ['{', '['], true)) {
+if (is_string($content) && json_decode($content) !== null) {

I think we should use json_decode because may be json has contains space first or last

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barryvdh barryvdh merged commit 185ca67 into barryvdh:master Sep 24, 2024
25 checks passed
@barryvdh barryvdh mentioned this pull request Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants