Skip to content

Commit 39f5f45

Browse files
authored
Fix escape of the error message in various output formatters
1 parent ac7b886 commit 39f5f45

12 files changed

+53
-53
lines changed

src/Command/ErrorFormatter/JunitErrorFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public function formatErrors(
3737
$result .= $this->createTestCase(
3838
sprintf('%s:%s', $fileName, (string) $fileSpecificError->getLine()),
3939
'ERROR',
40-
$this->escape($fileSpecificError->getMessage()),
40+
$fileSpecificError->getMessage(),
4141
);
4242
}
4343

4444
foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
45-
$result .= $this->createTestCase('General error', 'ERROR', $this->escape($notFileSpecificError));
45+
$result .= $this->createTestCase('General error', 'ERROR', $notFileSpecificError);
4646
}
4747

4848
foreach ($analysisResult->getWarnings() as $warning) {
49-
$result .= $this->createTestCase('Warning', 'WARNING', $this->escape($warning));
49+
$result .= $this->createTestCase('Warning', 'WARNING', $warning);
5050
}
5151

5252
if (!$analysisResult->hasErrors()) {

src/Command/ErrorFormatter/TableErrorFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ public function formatErrors(
153153
}
154154

155155
if (count($analysisResult->getNotFileSpecificErrors()) > 0) {
156-
$style->table(['', 'Error'], array_map(static fn (string $error): array => ['', $error], $analysisResult->getNotFileSpecificErrors()));
156+
$style->table(['', 'Error'], array_map(static fn (string $error): array => ['', OutputFormatter::escape($error)], $analysisResult->getNotFileSpecificErrors()));
157157
}
158158

159159
$warningsCount = count($analysisResult->getWarnings());
160160
if ($warningsCount > 0) {
161-
$style->table(['', 'Warning'], array_map(static fn (string $warning): array => ['', $warning], $analysisResult->getWarnings()));
161+
$style->table(['', 'Warning'], array_map(static fn (string $warning): array => ['', OutputFormatter::escape($warning)], $analysisResult->getWarnings()));
162162
}
163163

164164
$finalMessage = sprintf($analysisResult->getTotalErrorsCount() === 1 ? 'Found %d error' : 'Found %d errors', $analysisResult->getTotalErrorsCount());

src/Testing/ErrorFormatterTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
8080

8181
$fileErrors = array_slice([
8282
new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4),
83-
new Error('Foo', self::DIRECTORY_PATH . '/foo.php', 1),
83+
new Error('Foo<Bar>', self::DIRECTORY_PATH . '/foo.php', 1),
8484
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5, true, null, null, 'a tip'),
8585
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
8686
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', null),
8787
], 0, $numFileErrors);
8888

8989
$genericErrors = array_slice([
9090
'first generic error',
91-
'second generic error',
91+
'second generic<error>',
9292
], 0, $numGenericErrors);
9393

9494
return new AnalysisResult(

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function dataFormatterOutputProvider(): iterable
7474
'path' => 'foo.php',
7575
],
7676
[
77-
'message' => '#^Foo$#',
77+
'message' => '#^Foo\<Bar\>$#',
7878
'count' => 1,
7979
'path' => 'foo.php',
8080
],
@@ -103,7 +103,7 @@ public function dataFormatterOutputProvider(): iterable
103103
'path' => 'foo.php',
104104
],
105105
[
106-
'message' => '#^Foo$#',
106+
'message' => '#^Foo\<Bar\>$#',
107107
'count' => 1,
108108
'path' => 'foo.php',
109109
],

tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function dataFormatterOutputProvider(): iterable
6464
<error line="4" column="1" severity="error" message="Foo"/>
6565
</file>
6666
<file name="foo.php">
67-
<error line="1" column="1" severity="error" message="Foo"/>
67+
<error line="1" column="1" severity="error" message="Foo&lt;Bar&gt;"/>
6868
<error line="5" column="1" severity="error" message="Bar Bar2"/>
6969
</file>
7070
</checkstyle>
@@ -80,7 +80,7 @@ public function dataFormatterOutputProvider(): iterable
8080
<checkstyle>
8181
<file>
8282
<error message="first generic error" severity="error"/>
83-
<error message="second generic error" severity="error"/>
83+
<error message="second generic&lt;error&gt;" severity="error"/>
8484
</file>
8585
</checkstyle>
8686
',
@@ -98,12 +98,12 @@ public function dataFormatterOutputProvider(): iterable
9898
<error line="4" column="1" severity="error" message="Foo"/>
9999
</file>
100100
<file name="foo.php">
101-
<error line="1" column="1" severity="error" message="Foo"/>
101+
<error line="1" column="1" severity="error" message="Foo&lt;Bar&gt;"/>
102102
<error line="5" column="1" severity="error" message="Bar Bar2"/>
103103
</file>
104104
<file>
105105
<error message="first generic error" severity="error"/>
106-
<error message="second generic error" severity="error"/>
106+
<error message="second generic&lt;error&gt;" severity="error"/>
107107
</file>
108108
</checkstyle>
109109
',

tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function dataFormatterOutputProvider(): iterable
4545
0,
4646
'::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
4747
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
48-
::error file=foo.php,line=1,col=0::Foo
48+
::error file=foo.php,line=1,col=0::Foo<Bar>
4949
::error file=foo.php,line=5,col=0::Bar%0ABar2
5050
',
5151
];
@@ -56,7 +56,7 @@ public function dataFormatterOutputProvider(): iterable
5656
0,
5757
2,
5858
'::error ::first generic error
59-
::error ::second generic error
59+
::error ::second generic<error>
6060
',
6161
];
6262

@@ -67,10 +67,10 @@ public function dataFormatterOutputProvider(): iterable
6767
2,
6868
'::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
6969
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
70-
::error file=foo.php,line=1,col=0::Foo
70+
::error file=foo.php,line=1,col=0::Foo<Bar>
7171
::error file=foo.php,line=5,col=0::Bar%0ABar2
7272
::error ::first generic error
73-
::error ::second generic error
73+
::error ::second generic<error>
7474
',
7575
];
7676
}

tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function dataFormatterOutputProvider(): iterable
8888
}
8989
},
9090
{
91-
"description": "Foo",
92-
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
91+
"description": "Foo<Bar>",
92+
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
9393
"severity": "major",
9494
"location": {
9595
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
@@ -152,8 +152,8 @@ public function dataFormatterOutputProvider(): iterable
152152
}
153153
},
154154
{
155-
"description": "Foo",
156-
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
155+
"description": "Foo<Bar>",
156+
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
157157
"severity": "major",
158158
"location": {
159159
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
@@ -194,8 +194,8 @@ public function dataFormatterOutputProvider(): iterable
194194
}
195195
},
196196
{
197-
"description": "second generic error",
198-
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
197+
"description": "second generic<error>",
198+
"fingerprint": "adc18b2c27b0ecad40aed7975b165cbe357f0cbba58582af91c0a2e7fa5d77ab",
199199
"severity": "major",
200200
"location": {
201201
"path": "",
@@ -236,8 +236,8 @@ public function dataFormatterOutputProvider(): iterable
236236
}
237237
},
238238
{
239-
"description": "Foo",
240-
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
239+
"description": "Foo<Bar>",
240+
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
241241
"severity": "major",
242242
"location": {
243243
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
@@ -269,8 +269,8 @@ public function dataFormatterOutputProvider(): iterable
269269
}
270270
},
271271
{
272-
"description": "second generic error",
273-
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
272+
"description": "second generic<error>",
273+
"fingerprint": "adc18b2c27b0ecad40aed7975b165cbe357f0cbba58582af91c0a2e7fa5d77ab",
274274
"severity": "major",
275275
"location": {
276276
"path": "",

tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function dataFormatterOutputProvider(): iterable
105105
"errors":2,
106106
"messages":[
107107
{
108-
"message": "Foo",
108+
"message": "Foo<Bar>",
109109
"line": 1,
110110
"ignorable": true
111111
},
@@ -136,7 +136,7 @@ public function dataFormatterOutputProvider(): iterable
136136
"files":[],
137137
"errors": [
138138
"first generic error",
139-
"second generic error"
139+
"second generic<error>"
140140
]
141141
}',
142142
];
@@ -172,7 +172,7 @@ public function dataFormatterOutputProvider(): iterable
172172
"errors":2,
173173
"messages":[
174174
{
175-
"message": "Foo",
175+
"message": "Foo<Bar>",
176176
"line": 1,
177177
"ignorable": true
178178
},
@@ -187,7 +187,7 @@ public function dataFormatterOutputProvider(): iterable
187187
},
188188
"errors": [
189189
"first generic error",
190-
"second generic error"
190+
"second generic<error>"
191191
]
192192
}',
193193
];

tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function dataFormatterOutputProvider(): Generator
7474
<failure type="ERROR" message="Foo" />
7575
</testcase>
7676
<testcase name="foo.php:1">
77-
<failure type="ERROR" message="Foo"/>
77+
<failure type="ERROR" message="Foo&lt;Bar&gt;"/>
7878
</testcase>
7979
<testcase name="foo.php:5">
8080
<failure type="ERROR" message="Bar Bar2"/>
@@ -93,7 +93,7 @@ public function dataFormatterOutputProvider(): Generator
9393
<failure type="ERROR" message="first generic error" />
9494
</testcase>
9595
<testcase name="General error">
96-
<failure type="ERROR" message="second generic error"/>
96+
<failure type="ERROR" message="second generic&lt;error&gt;"/>
9797
</testcase>
9898
</testsuite>
9999
',
@@ -112,7 +112,7 @@ public function dataFormatterOutputProvider(): Generator
112112
<failure type="ERROR" message="Foo" />
113113
</testcase>
114114
<testcase name="foo.php:1">
115-
<failure type="ERROR" message="Foo"/>
115+
<failure type="ERROR" message="Foo&lt;Bar&gt;"/>
116116
</testcase>
117117
<testcase name="foo.php:5">
118118
<failure type="ERROR" message="Bar Bar2"/>
@@ -121,7 +121,7 @@ public function dataFormatterOutputProvider(): Generator
121121
<failure type="ERROR" message="first generic error" />
122122
</testcase>
123123
<testcase name="General error">
124-
<failure type="ERROR" message="second generic error"/>
124+
<failure type="ERROR" message="second generic&lt;error&gt;"/>
125125
</testcase>
126126
</testsuite>
127127
',

tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function dataFormatterOutputProvider(): iterable
4141
0,
4242
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2:Bar' . "\nBar2\n" .
4343
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4:Foo' . "\n" .
44-
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo' . "\n" .
44+
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo<Bar>' . "\n" .
4545
'/data/folder/with space/and unicode 😃/project/foo.php:5:Bar' . "\nBar2\n",
4646
];
4747

@@ -51,7 +51,7 @@ public function dataFormatterOutputProvider(): iterable
5151
0,
5252
2,
5353
'?:?:first generic error' . "\n" .
54-
'?:?:second generic error' . "\n",
54+
'?:?:second generic<error>' . "\n",
5555
];
5656

5757
yield [
@@ -60,10 +60,10 @@ public function dataFormatterOutputProvider(): iterable
6060
4,
6161
2,
6262
'?:?:first generic error' . "\n" .
63-
'?:?:second generic error' . "\n" .
63+
'?:?:second generic<error>' . "\n" .
6464
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2:Bar' . "\nBar2\n" .
6565
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4:Foo' . "\n" .
66-
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo' . "\n" .
66+
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo<Bar>' . "\n" .
6767
'/data/folder/with space/and unicode 😃/project/foo.php:5:Bar' . "\nBar2\n",
6868
];
6969
}

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function dataFormatterOutputProvider(): iterable
9494
------ ----------
9595
Line foo.php
9696
------ ----------
97-
1 Foo
97+
1 Foo<Bar>
9898
5 Bar
9999
Bar2
100100
💡 a tip
@@ -111,12 +111,12 @@ public function dataFormatterOutputProvider(): iterable
111111
'numFileErrors' => 0,
112112
'numGenericErrors' => 2,
113113
'extraEnvVars' => [],
114-
'expected' => ' -- ----------------------
114+
'expected' => ' -- -----------------------
115115
Error
116-
-- ----------------------
116+
-- -----------------------
117117
first generic error
118-
second generic error
119-
-- ----------------------
118+
second generic<error>
119+
-- -----------------------
120120
121121
122122
[ERROR] Found 2 errors
@@ -141,18 +141,18 @@ public function dataFormatterOutputProvider(): iterable
141141
------ ----------
142142
Line foo.php
143143
------ ----------
144-
1 Foo
144+
1 Foo<Bar>
145145
5 Bar
146146
Bar2
147147
💡 a tip
148148
------ ----------
149149
150-
-- ----------------------
150+
-- -----------------------
151151
Error
152-
-- ----------------------
152+
-- -----------------------
153153
first generic error
154-
second generic error
155-
-- ----------------------
154+
second generic<error>
155+
-- -----------------------
156156
157157
[ERROR] Found 6 errors
158158

tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function dataFormatterOutputProvider(): iterable
4848
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
4949
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
5050
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
51-
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
51+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
5252
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
5353
',
5454
];
@@ -60,7 +60,7 @@ public function dataFormatterOutputProvider(): iterable
6060
2,
6161
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
6262
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
63-
##teamcity[inspection typeId=\'phpstan\' message=\'second generic error\' file=\'.\' SEVERITY=\'ERROR\']
63+
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
6464
',
6565
];
6666

@@ -72,10 +72,10 @@ public function dataFormatterOutputProvider(): iterable
7272
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
7373
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
7474
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
75-
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
75+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
7676
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
7777
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
78-
##teamcity[inspection typeId=\'phpstan\' message=\'second generic error\' file=\'.\' SEVERITY=\'ERROR\']
78+
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
7979
',
8080
];
8181
}

0 commit comments

Comments
 (0)