Commit c12345d
committed
bug #62805 [VarDumper] Fix dumper selection for Accept: */* requests (apoca)
This PR was squashed before being merged into the 7.4 branch.
Discussion
----------
[VarDumper] Fix dumper selection for Accept: */* requests
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix #62787
| License | MIT
## What does this fix?
Fixes incorrect dumper selection when `Accept: */*` header is present in HTTP requests, causing `dd()` and `dump()` output to disappear in browsers.
## The Problem
Since version 7.4.0 (PR #58070), when an HTTP request includes `Accept: */*` header, the dumper selection logic incorrectly chooses `CliDumper` instead of `HtmlDumper`. This causes dumps to be sent to STDOUT instead of being rendered in the browser response.
**Affected scenario:**
```php
// Browser makes request with Accept: */*
// dd(['test' => 123]) produces blank page instead of showing dump
```
Common with:
- AJAX requests without explicit Accept header
- API clients (Postman, Insomnia)
- cURL without `-H "Accept: text/html"`
- PHP-FPM environments
## Root Cause
Current code only checks if Accept contains literal string `'html'`:
```php
str_contains($_SERVER['HTTP_ACCEPT'], 'html') ? new HtmlDumper() : new CliDumper()
```
According to [RFC 9110 Section 12.5.1](https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.1), `*/*` means "accept any media type", including `text/html`.
## Solution
Added explicit check for wildcard pattern:
```php
$accept = $_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html');
$dumper = (str_contains($accept, 'html') || str_contains($accept, '*/*')) ? new HtmlDumper() : new CliDumper();
```
**Before:** `Accept: */*` → ❌ CliDumper (blank page)
**After:** `Accept: */*` → ✅ HtmlDumper (dump visible)
## Backward Compatibility
✅ Fully backward compatible - only fixes broken behavior introduced in 7.4.0
**Test coverage:**
- `Accept: text/html` → HtmlDumper (unchanged)
- `Accept: */*` → HtmlDumper (fixed)
- `Accept: application/json` → CliDumper (unchanged)
- CLI SAPI → CliDumper (unchanged)
Commits
-------
bc7b547 [VarDumper] Fix dumper selection for Accept: */* requestsFile tree
2 files changed
+20
-2
lines changed- src/Symfony/Component/VarDumper
- Tests/Dumper/functions
2 files changed
+20
-2
lines changedLines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
0 commit comments