Skip to content

Commit

Permalink
Use HTML-escaped messages in CheckstyleOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap authored and jrfnl committed Dec 6, 2021
1 parent dd43959 commit 490078e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign
sprintf(
' <error line="%d" severity="ERROR" message="%s" source="%s" />',
$fileError['line'],
$fileError['message'],
htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'),
$fileError['source']
) .
PHP_EOL
Expand Down
22 changes: 22 additions & 0 deletions tests/Output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require __DIR__ . '/../vendor/autoload.php';

use JakubOnderka\PhpParallelLint\ErrorFormatter;
use JakubOnderka\PhpParallelLint\GitLabOutput;
use JakubOnderka\PhpParallelLint\CheckstyleOutput;
use JakubOnderka\PhpParallelLint\IWriter;
use JakubOnderka\PhpParallelLint\Result;
use JakubOnderka\PhpParallelLint\SyntaxError;
Expand Down Expand Up @@ -46,6 +47,27 @@ class OutputTest extends Tester\TestCase
}
}

public function testCheckstyleOutput()
{
$errors = array(
new JakubOnderka\PhpParallelLint\SyntaxError(
'sample.php',
'Parse error: syntax error, unexpected \'"\' in ./sample.php on line 3'
),
);

$result = new Result($errors, array(), array(), 0);
$writer = new TestWriter();
$output = new CheckstyleOutput($writer);

$output->writeResult($result, new ErrorFormatter(), true);
$xml = $writer->getLogs();
$parsed = @simplexml_load_string($xml);

Assert::contains("unexpected '&quot;'", $xml);
Assert::type('SimpleXMLElement', $parsed);
}

public function getGitLabOutputData()
{
return array(
Expand Down

0 comments on commit 490078e

Please sign in to comment.