Skip to content

Commit 92d54f8

Browse files
committed
Escape non-printable characters in the junit XML output
XML doesn't allow most of the characters < 0x20 and binary output breaks XML parsers. Such characters are not allowed as entities either, so the generated entities are escaped in order to be printed as text.
1 parent 1696166 commit 92d54f8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

run-tests.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,9 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
27012701
junit_suite_record($suite, 'execution_time', $time);
27022702

27032703
$escaped_details = htmlspecialchars($details, ENT_QUOTES, 'UTF-8');
2704+
$escaped_details = preg_replace_callback('/[\0-\x08\x0B\x0C\x0E-\x1F]/', function ($c) {
2705+
return sprintf('[[0x%02x]]', ord($c[0]));
2706+
}, $escaped_details);
27042707
$escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
27052708

27062709
$escaped_test_name = basename($file_name) . ' - ' . htmlspecialchars($test_name, ENT_QUOTES);

0 commit comments

Comments
 (0)