Skip to content

Commit c99b7f8

Browse files
authored
encode newlines in GithubErrorFormatter
1 parent 92b57a5 commit c99b7f8

11 files changed

+57
-38
lines changed

src/Command/ErrorFormatter/GithubErrorFormatter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
4141
});
4242

4343
$message = $fileSpecificError->getMessage();
44+
// newlines need to be encoded
45+
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
46+
$message = str_replace("\n", '%0A', $message);
4447

4548
$line = sprintf('::error %s::%s', implode(',', $metas), $message);
4649

@@ -49,13 +52,21 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
4952
}
5053

5154
foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
55+
// newlines need to be encoded
56+
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
57+
$notFileSpecificError = str_replace("\n", '%0A', $notFileSpecificError);
58+
5259
$line = sprintf('::error ::%s', $notFileSpecificError);
5360

5461
$output->writeRaw($line);
5562
$output->writeLineFormatted('');
5663
}
5764

5865
foreach ($analysisResult->getWarnings() as $warning) {
66+
// newlines need to be encoded
67+
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
68+
$warning = str_replace("\n", '%0A', $warning);
69+
5970
$line = sprintf('::warning ::%s', $warning);
6071

6172
$output->writeRaw($line);

src/Testing/ErrorFormatterTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
6767
$fileErrors = array_slice([
6868
new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4),
6969
new Error('Foo', self::DIRECTORY_PATH . '/foo.php', 1),
70-
new Error('Bar', self::DIRECTORY_PATH . '/foo.php', 5),
71-
new Error('Bar', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
70+
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5),
71+
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
7272
], 0, $numFileErrors);
7373

7474
$genericErrors = array_slice([

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function dataFormatterOutputProvider(): iterable
4242
0,
4343
[
4444
[
45-
'message' => '#^Bar$#',
45+
'message' => "#^Bar\nBar2$#",
4646
'count' => 1,
4747
'path' => 'folder with unicode 😃/file name with "spaces" and unicode 😃.php',
4848
],
@@ -57,7 +57,7 @@ public function dataFormatterOutputProvider(): iterable
5757
'path' => 'foo.php',
5858
],
5959
[
60-
'message' => '#^Bar$#',
60+
'message' => "#^Bar\nBar2$#",
6161
'count' => 1,
6262
'path' => 'foo.php',
6363
],
@@ -71,7 +71,7 @@ public function dataFormatterOutputProvider(): iterable
7171
2,
7272
[
7373
[
74-
'message' => '#^Bar$#',
74+
'message' => "#^Bar\nBar2$#",
7575
'count' => 1,
7676
'path' => 'folder with unicode 😃/file name with "spaces" and unicode 😃.php',
7777
],
@@ -86,7 +86,7 @@ public function dataFormatterOutputProvider(): iterable
8686
'path' => 'foo.php',
8787
],
8888
[
89-
'message' => '#^Bar$#',
89+
'message' => "#^Bar\nBar2$#",
9090
'count' => 1,
9191
'path' => 'foo.php',
9292
],

tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public function dataFormatterOutputProvider(): iterable
5959
'<?xml version="1.0" encoding="UTF-8"?>
6060
<checkstyle>
6161
<file name="folder with unicode 😃/file name with &quot;spaces&quot; and unicode 😃.php">
62-
<error line="2" column="1" severity="error" message="Bar"/>
62+
<error line="2" column="1" severity="error" message="Bar Bar2"/>
6363
<error line="4" column="1" severity="error" message="Foo"/>
6464
</file>
6565
<file name="foo.php">
6666
<error line="1" column="1" severity="error" message="Foo"/>
67-
<error line="5" column="1" severity="error" message="Bar"/>
67+
<error line="5" column="1" severity="error" message="Bar Bar2"/>
6868
</file>
6969
</checkstyle>
7070
',
@@ -93,12 +93,12 @@ public function dataFormatterOutputProvider(): iterable
9393
'<?xml version="1.0" encoding="UTF-8"?>
9494
<checkstyle>
9595
<file name="folder with unicode 😃/file name with &quot;spaces&quot; and unicode 😃.php">
96-
<error line="2" column="1" severity="error" message="Bar"/>
96+
<error line="2" column="1" severity="error" message="Bar Bar2"/>
9797
<error line="4" column="1" severity="error" message="Foo"/>
9898
</file>
9999
<file name="foo.php">
100100
<error line="1" column="1" severity="error" message="Foo"/>
101-
<error line="5" column="1" severity="error" message="Bar"/>
101+
<error line="5" column="1" severity="error" message="Bar Bar2"/>
102102
</file>
103103
<file>
104104
<error message="first generic error" severity="error"/>

tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function dataFormatterOutputProvider(): iterable
6464
Line folder with unicode 😃/file name with "spaces" and unicode 😃.php
6565
------ -----------------------------------------------------------------
6666
2 Bar
67+
Bar2
6768
4 Foo
6869
------ -----------------------------------------------------------------
6970
@@ -72,14 +73,15 @@ public function dataFormatterOutputProvider(): iterable
7273
------ ---------
7374
1 Foo
7475
5 Bar
76+
Bar2
7577
------ ---------
7678
7779
[ERROR] Found 4 errors
7880
79-
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar
81+
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
8082
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
8183
::error file=foo.php,line=1,col=0::Foo
82-
::error file=foo.php,line=5,col=0::Bar
84+
::error file=foo.php,line=5,col=0::Bar%0ABar2
8385
',
8486
];
8587

@@ -111,6 +113,7 @@ public function dataFormatterOutputProvider(): iterable
111113
Line folder with unicode 😃/file name with "spaces" and unicode 😃.php
112114
------ -----------------------------------------------------------------
113115
2 Bar
116+
Bar2
114117
4 Foo
115118
------ -----------------------------------------------------------------
116119
@@ -119,6 +122,7 @@ public function dataFormatterOutputProvider(): iterable
119122
------ ---------
120123
1 Foo
121124
5 Bar
125+
Bar2
122126
------ ---------
123127
124128
-- ----------------------
@@ -130,10 +134,10 @@ public function dataFormatterOutputProvider(): iterable
130134
131135
[ERROR] Found 6 errors
132136
133-
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar
137+
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
134138
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
135139
::error file=foo.php,line=1,col=0::Foo
136-
::error file=foo.php,line=5,col=0::Bar
140+
::error file=foo.php,line=5,col=0::Bar%0ABar2
137141
::error ::first generic error
138142
::error ::second generic error
139143
',

tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function dataFormatterOutputProvider(): iterable
6363
0,
6464
'[
6565
{
66-
"description": "Bar",
67-
"fingerprint": "d112f1651daa597592156359ef28c9a4b81a8a96dbded1c0f1009f5bbc2bda97",
66+
"description": "Bar\nBar2",
67+
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
6868
"location": {
6969
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
7070
"lines": {
@@ -93,8 +93,8 @@ public function dataFormatterOutputProvider(): iterable
9393
}
9494
},
9595
{
96-
"description": "Bar",
97-
"fingerprint": "d83022ee5bc7c71b6a4988ec47a377c9998b929d12d86fc71b745ec2b04c81e5",
96+
"description": "Bar\nBar2",
97+
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
9898
"location": {
9999
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
100100
"lines": {
@@ -141,8 +141,8 @@ public function dataFormatterOutputProvider(): iterable
141141
2,
142142
'[
143143
{
144-
"description": "Bar",
145-
"fingerprint": "d112f1651daa597592156359ef28c9a4b81a8a96dbded1c0f1009f5bbc2bda97",
144+
"description": "Bar\nBar2",
145+
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
146146
"location": {
147147
"path": "with space/and unicode \ud83d\ude03/project/folder with unicode \ud83d\ude03/file name with \"spaces\" and unicode \ud83d\ude03.php",
148148
"lines": {
@@ -171,8 +171,8 @@ public function dataFormatterOutputProvider(): iterable
171171
}
172172
},
173173
{
174-
"description": "Bar",
175-
"fingerprint": "d83022ee5bc7c71b6a4988ec47a377c9998b929d12d86fc71b745ec2b04c81e5",
174+
"description": "Bar\nBar2",
175+
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
176176
"location": {
177177
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
178178
"lines": {

tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function dataFormatterOutputProvider(): iterable
8686
"errors":2,
8787
"messages":[
8888
{
89-
"message": "Bar",
89+
"message": "Bar\nBar2",
9090
"line": 2,
9191
"ignorable": true
9292
},
@@ -106,7 +106,7 @@ public function dataFormatterOutputProvider(): iterable
106106
"ignorable": true
107107
},
108108
{
109-
"message": "Bar",
109+
"message": "Bar\nBar2",
110110
"line": 5,
111111
"ignorable": true
112112
}
@@ -152,7 +152,7 @@ public function dataFormatterOutputProvider(): iterable
152152
"errors":2,
153153
"messages":[
154154
{
155-
"message": "Bar",
155+
"message": "Bar\nBar2",
156156
"line": 2,
157157
"ignorable": true
158158
},
@@ -172,7 +172,7 @@ public function dataFormatterOutputProvider(): iterable
172172
"ignorable": true
173173
},
174174
{
175-
"message": "Bar",
175+
"message": "Bar\nBar2",
176176
"line": 5,
177177
"ignorable": true
178178
}

tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function dataFormatterOutputProvider(): Generator
6969
'<?xml version="1.0" encoding="UTF-8"?>
7070
<testsuite failures="4" name="phpstan" tests="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
7171
<testcase name="folder with unicode &#x1F603;/file name with &quot;spaces&quot; and unicode &#x1F603;.php:2">
72-
<failure type="ERROR" message="Bar" />
72+
<failure type="ERROR" message="Bar Bar2" />
7373
</testcase>
7474
<testcase name="folder with unicode &#x1F603;/file name with &quot;spaces&quot; and unicode &#x1F603;.php:4">
7575
<failure type="ERROR" message="Foo" />
@@ -78,7 +78,7 @@ public function dataFormatterOutputProvider(): Generator
7878
<failure type="ERROR" message="Foo"/>
7979
</testcase>
8080
<testcase name="foo.php:5">
81-
<failure type="ERROR" message="Bar"/>
81+
<failure type="ERROR" message="Bar Bar2"/>
8282
</testcase>
8383
</testsuite>
8484
',
@@ -107,7 +107,7 @@ public function dataFormatterOutputProvider(): Generator
107107
'<?xml version="1.0" encoding="UTF-8"?>
108108
<testsuite failures="6" name="phpstan" tests="6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
109109
<testcase name="folder with unicode &#x1F603;/file name with &quot;spaces&quot; and unicode &#x1F603;.php:2">
110-
<failure type="ERROR" message="Bar" />
110+
<failure type="ERROR" message="Bar Bar2" />
111111
</testcase>
112112
<testcase name="folder with unicode &#x1F603;/file name with &quot;spaces&quot; and unicode &#x1F603;.php:4">
113113
<failure type="ERROR" message="Foo" />
@@ -116,7 +116,7 @@ public function dataFormatterOutputProvider(): Generator
116116
<failure type="ERROR" message="Foo"/>
117117
</testcase>
118118
<testcase name="foo.php:5">
119-
<failure type="ERROR" message="Bar"/>
119+
<failure type="ERROR" message="Bar Bar2"/>
120120
</testcase>
121121
<testcase name="General error">
122122
<failure type="ERROR" message="first generic error" />

tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php

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

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

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function dataFormatterOutputProvider(): iterable
6262
Line folder with unicode 😃/file name with "spaces" and unicode 😃.php
6363
------ -----------------------------------------------------------------
6464
2 Bar
65+
Bar2
6566
4 Foo
6667
------ -----------------------------------------------------------------
6768
@@ -70,6 +71,7 @@ public function dataFormatterOutputProvider(): iterable
7071
------ ---------
7172
1 Foo
7273
5 Bar
74+
Bar2
7375
------ ---------
7476
7577
[ERROR] Found 4 errors
@@ -103,6 +105,7 @@ public function dataFormatterOutputProvider(): iterable
103105
Line folder with unicode 😃/file name with "spaces" and unicode 😃.php
104106
------ -----------------------------------------------------------------
105107
2 Bar
108+
Bar2
106109
4 Foo
107110
------ -----------------------------------------------------------------
108111
@@ -111,6 +114,7 @@ public function dataFormatterOutputProvider(): iterable
111114
------ ---------
112115
1 Foo
113116
5 Bar
117+
Bar2
114118
------ ---------
115119
116120
-- ----------------------

0 commit comments

Comments
 (0)