Skip to content

Commit d81cb77

Browse files
schlndhondrejmirtes
authored andcommitted
fix bug 13292
The patch is from symfony/symfony#61242 rebased onto symfony/console 5.4
1 parent 1f150cc commit d81cb77

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
],
130130
"react/http": [
131131
"patches/Sender.patch"
132+
],
133+
"symfony/console": [
134+
"patches/OutputFormatter.patch"
132135
]
133136
}
134137
},

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patches/OutputFormatter.patch

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--- Formatter/OutputFormatter.php
2+
+++ Formatter/OutputFormatter.php
3+
@@ -12,6 +12,7 @@
4+
namespace Symfony\Component\Console\Formatter;
5+
6+
use Symfony\Component\Console\Exception\InvalidArgumentException;
7+
+use Symfony\Component\Console\Helper\Helper;
8+
9+
use function Symfony\Component\String\b;
10+
11+
@@ -160,9 +161,11 @@ class OutputFormatter implements WrappableOutputFormatterInterface
12+
continue;
13+
}
14+
15+
+ // convert byte position to character position.
16+
+ $pos = Helper::length(substr($message, 0, $pos));
17+
// add the text up to the next tag
18+
- $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength);
19+
- $offset = $pos + \strlen($text);
20+
+ $output .= $this->applyCurrentStyle(Helper::substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength);
21+
+ $offset = $pos + Helper::length($text);
22+
23+
// opening tag?
24+
if ($open = '/' != $text[1]) {
25+
@@ -183,7 +186,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
26+
}
27+
}
28+
29+
- $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength);
30+
+ $output .= $this->applyCurrentStyle(Helper::substr($message, $offset), $output, $width, $currentLineLength);
31+
32+
return strtr($output, ["\0" => '\\', '\\<' => '<', '\\>' => '>']);
33+
}
34+
@@ -253,8 +256,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface
35+
}
36+
37+
if ($currentLineLength) {
38+
- $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n";
39+
- $text = substr($text, $i);
40+
+ $prefix = Helper::substr($text, 0, $i = $width - $currentLineLength)."\n";
41+
+ $text = Helper::substr($text, $i);
42+
} else {
43+
$prefix = '';
44+
}
45+
@@ -270,7 +273,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
46+
$lines = explode("\n", $text);
47+
48+
foreach ($lines as $line) {
49+
- $currentLineLength += \strlen($line);
50+
+ $currentLineLength += Helper::length($line);
51+
if ($width <= $currentLineLength) {
52+
$currentLineLength = 0;
53+
}
54+
--- Helper/Helper.php
55+
+++ Helper/Helper.php
56+
@@ -100,6 +100,14 @@ abstract class Helper implements HelperInterface
57+
{
58+
$string ?? $string = '';
59+
60+
+ if (preg_match('//u', $string)) {
61+
+ $result = grapheme_substr((new UnicodeString($string))->toString(), $from, $length);
62+
+
63+
+ return false === $result
64+
+ ? ''
65+
+ : $result;
66+
+ }
67+
+
68+
if (false === $encoding = mb_detect_encoding($string, null, true)) {
69+
return substr($string, $from, $length);
70+
}

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,36 @@ public function testBug6727(): void
320320
self::expectNotToPerformAssertions();
321321
}
322322

323+
public function testBug13292(): void
324+
{
325+
putenv('COLUMNS=200');
326+
$formatter = $this->createErrorFormatter(null);
327+
$formatter->formatErrors(
328+
new AnalysisResult(
329+
[
330+
new Error(
331+
'Parameter #1 $arrayabc of method Abcdefghijklmnopqrstuvwxyzabcdefghijk::translateAbcdefgh() expects array{status: int, error: string, date?: string}, non-empty-array<mixed, mixed> given.',
332+
'Foo.php',
333+
5,
334+
identifier: 'argument.type',
335+
),
336+
],
337+
[],
338+
[],
339+
[],
340+
[],
341+
false,
342+
null,
343+
true,
344+
0,
345+
false,
346+
[],
347+
),
348+
$this->getOutput(),
349+
);
350+
self::expectNotToPerformAssertions();
351+
}
352+
323353
private function createErrorFormatter(?string $editorUrl, ?string $editorUrlTitle = null): TableErrorFormatter
324354
{
325355
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/');

0 commit comments

Comments
 (0)