Skip to content

Commit bc7b547

Browse files
apocanicolas-grekas
authored andcommitted
[VarDumper] Fix dumper selection for Accept: */* requests
1 parent 1f337e8 commit bc7b547

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test dump() with "Accept: */*" uses HTML dumper
3+
--FILE--
4+
<?php
5+
putenv('NO_COLOR=1');
6+
7+
$vendor = __DIR__;
8+
while (!file_exists($vendor.'/vendor')) {
9+
$vendor = \dirname($vendor);
10+
}
11+
require $vendor.'/vendor/autoload.php';
12+
13+
$_SERVER['HTTP_ACCEPT'] = '*/*';
14+
dump('Test with wildcard');
15+
--EXPECTF--
16+
%a>Test with wildcard</%a

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ private static function register(): void
7676
case 'server' === $format:
7777
case $format && 'tcp' === parse_url($format, \PHP_URL_SCHEME):
7878
$host = 'server' === $format ? $_SERVER['VAR_DUMPER_SERVER'] ?? '127.0.0.1:9912' : $format;
79-
$dumper = str_contains($_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html'), 'html') ? new HtmlDumper() : new CliDumper();
79+
$accept = $_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html');
80+
$dumper = str_contains($accept, 'html') || str_contains($accept, '*/*') ? new HtmlDumper() : new CliDumper();
8081
$dumper = new ServerDumper($host, $dumper, self::getDefaultContextProviders());
8182
break;
8283
default:
83-
$dumper = str_contains($_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html'), 'html') ? new HtmlDumper() : new CliDumper();
84+
$accept = $_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html');
85+
$dumper = str_contains($accept, 'html') || str_contains($accept, '*/*') ? new HtmlDumper() : new CliDumper();
8486
}
8587

8688
if (!$dumper instanceof ServerDumper) {

0 commit comments

Comments
 (0)