Skip to content

Commit 2792b52

Browse files
committed
Use HTML-escaped messages in CheckstyleOutput
fixes php-parallel-lint#72
1 parent 02a09f1 commit 2792b52

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Output.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign
441441
sprintf(
442442
' <error line="%d" severity="ERROR" message="%s" source="%s" />',
443443
$fileError['line'],
444-
$fileError['message'],
444+
htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'),
445445
$fileError['source']
446446
) .
447447
PHP_EOL

tests/Output.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require __DIR__ . '/../vendor/autoload.php';
88

99
use JakubOnderka\PhpParallelLint\ErrorFormatter;
1010
use JakubOnderka\PhpParallelLint\GitLabOutput;
11+
use JakubOnderka\PhpParallelLint\CheckstyleOutput;
1112
use JakubOnderka\PhpParallelLint\IWriter;
1213
use JakubOnderka\PhpParallelLint\Result;
1314
use JakubOnderka\PhpParallelLint\SyntaxError;
@@ -46,6 +47,27 @@ class OutputTest extends Tester\TestCase
4647
}
4748
}
4849

50+
public function testCheckstyleOutput()
51+
{
52+
$errors = array(
53+
new JakubOnderka\PhpParallelLint\SyntaxError(
54+
'sample.php',
55+
'Parse error: syntax error, unexpected \'"\' in ./sample.php on line 3'
56+
),
57+
);
58+
59+
$result = new Result($errors, array(), array(), 0);
60+
$writer = new TestWriter();
61+
$output = new CheckstyleOutput($writer);
62+
63+
$output->writeResult($result, new ErrorFormatter(), true);
64+
$xml = $writer->getLogs();
65+
$parsed = @simplexml_load_string($xml);
66+
67+
Assert::contains("unexpected '&quot;'", $xml);
68+
Assert::type('SimpleXMLElement', $parsed);
69+
}
70+
4971
public function getGitLabOutputData()
5072
{
5173
return array(

0 commit comments

Comments
 (0)