Skip to content

Commit 3e6d2c8

Browse files
committed
Report/XML: bug fix for output on Windows
It looks like the `XMLWriter` extension does not respect the OS-specific `PHP_EOL` character, but always uses `\n`, though I have not been able to test this on various OS-es to confirm. This could be regarded as a bug in PHP itself which may or may not be fixed at some point. With the above in mind, I have created a fix which contains some redundancy, but should be stable on all OS-es, including if/when the PHP native issue would be fixed. Alternatively, the whole snippet could be replaced by the code on line 81 of the patch. Fixes 2526
1 parent 07ccaf2 commit 3e6d2c8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Reports/Xml.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
7575
// add that manually later. We only have it in here to
7676
// properly set the encoding.
7777
$content = $out->flush();
78-
$content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
78+
if (strpos($content, PHP_EOL) !== false) {
79+
$content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
80+
} else if (strpos($content, "\n") !== false) {
81+
$content = substr($content, (strpos($content, "\n") + 1));
82+
}
83+
7984
echo $content;
8085

8186
return true;

0 commit comments

Comments
 (0)