Skip to content

Commit 1d70161

Browse files
Merge branch '6.4' into 7.2
* 6.4: [VarDumper] Fix dumping on systems that don't have a working iconv [Console] fix profiler with overridden `run()` method [Config] Fix support for attributes on class constants and enum cases
2 parents a84a802 + 6e816f9 commit 1d70161

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

Dumper/AbstractDumper.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,48 @@ protected function utf8Encode(?string $s): ?string
185185
return $s;
186186
}
187187

188-
if (!\function_exists('iconv')) {
189-
throw new \RuntimeException('Unable to convert a non-UTF-8 string to UTF-8: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.');
188+
if (\function_exists('iconv')) {
189+
if (false !== $c = @iconv($this->charset, 'UTF-8', $s)) {
190+
return $c;
191+
}
192+
if ('CP1252' !== $this->charset && false !== $c = @iconv('CP1252', 'UTF-8', $s)) {
193+
return $c;
194+
}
190195
}
191196

192-
if (false !== $c = @iconv($this->charset, 'UTF-8', $s)) {
193-
return $c;
197+
$s .= $s;
198+
$len = \strlen($s);
199+
$mapCp1252 = false;
200+
201+
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
202+
if ($s[$i] < "\x80") {
203+
$s[$j] = $s[$i];
204+
} elseif ($s[$i] < "\xC0") {
205+
$s[$j] = "\xC2";
206+
$s[++$j] = $s[$i];
207+
if ($s[$i] < "\xA0") {
208+
$mapCp1252 = true;
209+
}
210+
} else {
211+
$s[$j] = "\xC3";
212+
$s[++$j] = \chr(\ord($s[$i]) - 64);
213+
}
194214
}
195-
if ('CP1252' !== $this->charset && false !== $c = @iconv('CP1252', 'UTF-8', $s)) {
196-
return $c;
215+
216+
$s = substr($s, 0, $j);
217+
218+
if (!$mapCp1252) {
219+
return $s;
197220
}
198221

199-
return iconv('CP850', 'UTF-8', $s);
222+
return strtr($s, [
223+
"\xC2\x80" => '', "\xC2\x82" => '', "\xC2\x83" => 'ƒ', "\xC2\x84" => '',
224+
"\xC2\x85" => '', "\xC2\x86" => '', "\xC2\x87" => '', "\xC2\x88" => 'ˆ',
225+
"\xC2\x89" => '', "\xC2\x8A" => 'Š', "\xC2\x8B" => '', "\xC2\x8C" => 'Œ',
226+
"\xC2\x8D" => 'Ž', "\xC2\x91" => '', "\xC2\x92" => '', "\xC2\x93" => '',
227+
"\xC2\x94" => '', "\xC2\x95" => '', "\xC2\x96" => '', "\xC2\x97" => '',
228+
"\xC2\x98" => '˜', "\xC2\x99" => '', "\xC2\x9A" => 'š', "\xC2\x9B" => '',
229+
"\xC2\x9C" => 'œ', "\xC2\x9E" => 'ž',
230+
]);
200231
}
201232
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"symfony/polyfill-mbstring": "~1.0"
2121
},
2222
"require-dev": {
23-
"ext-iconv": "*",
2423
"symfony/console": "^6.4|^7.0",
2524
"symfony/http-kernel": "^6.4|^7.0",
2625
"symfony/process": "^6.4|^7.0",

0 commit comments

Comments
 (0)