Skip to content

Commit

Permalink
Fixed broken XML junit output due to escaping of CDATA sections
Browse files Browse the repository at this point in the history
I've removed CDATA and used htmlspecialchars as the output might not be UTF-8 safe, as pointed out by ircmaxell in 26b37f1
  • Loading branch information
mbeccati committed May 27, 2014
1 parent d184f07 commit 1696166
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ function run_test($php, $file, $env)
}

$message = !empty($m[1]) ? $m[1] : '';
junit_mark_test_as('SKIP', $shortname, $tested, null, "<![CDATA[\n$message\n]]>");
junit_mark_test_as('SKIP', $shortname, $tested, null, $message);
return 'SKIPPED';
}

Expand All @@ -1554,7 +1554,7 @@ function run_test($php, $file, $env)
) {
$message = "ext/zlib required";
show_result('SKIP', $tested, $tested_file, "reason: $message", $temp_filenames);
junit_mark_test_as('SKIP', $shortname, $tested, null, "<![CDATA[\n$message\n]]>");
junit_mark_test_as('SKIP', $shortname, $tested, null, $message);
return 'SKIPPED';
}

Expand Down Expand Up @@ -2122,7 +2122,7 @@ function run_test($php, $file, $env)
$php = $old_php;
}

$diff = empty($diff) ? '' : "<![CDATA[\n " . preg_replace('/\e/', '<esc>', $diff) . "\n]]>";
$diff = empty($diff) ? '' : preg_replace('/\e/', '<esc>', $diff);

junit_mark_test_as($restype, str_replace($cwd . '/', '', $tested_file), $tested, null, $info, $diff);

Expand Down Expand Up @@ -2701,6 +2701,7 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
junit_suite_record($suite, 'execution_time', $time);

$escaped_details = htmlspecialchars($details, ENT_QUOTES, 'UTF-8');
$escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');

$escaped_test_name = basename($file_name) . ' - ' . htmlspecialchars($test_name, ENT_QUOTES);
$JUNIT['files'][$file_name]['xml'] = "<testcase classname='$suite' name='$escaped_test_name' time='$time'>\n";
Expand All @@ -2717,16 +2718,16 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
junit_suite_record($suite, 'test_pass');
} elseif ('BORK' == $type) {
junit_suite_record($suite, 'test_error');
$JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$message'/>\n";
$JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$escaped_message'/>\n";
} elseif ('SKIP' == $type) {
junit_suite_record($suite, 'test_skip');
$JUNIT['files'][$file_name]['xml'] .= "<skipped>$message</skipped>\n";
$JUNIT['files'][$file_name]['xml'] .= "<skipped>$escaped_message</skipped>\n";
} elseif('FAIL' == $type) {
junit_suite_record($suite, 'test_fail');
$JUNIT['files'][$file_name]['xml'] .= "<failure type='$output_type' message='$message'>$escaped_details</failure>\n";
$JUNIT['files'][$file_name]['xml'] .= "<failure type='$output_type' message='$escaped_message'>$escaped_details</failure>\n";
} else {
junit_suite_record($suite, 'test_error');
$JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$message'>$escaped_details</error>\n";
$JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$escaped_message'>$escaped_details</error>\n";
}

$JUNIT['files'][$file_name]['xml'] .= "</testcase>\n";
Expand Down

0 comments on commit 1696166

Please sign in to comment.