]> granicus.if.org Git - php/commitdiff
Fix two issues with run-tests.php
authorAnthony Ferrara <ircmaxell@php.net>
Sat, 7 Jul 2012 02:37:50 +0000 (22:37 -0400)
committerAnthony Ferrara <ircmaxell@php.net>
Sat, 7 Jul 2012 02:37:50 +0000 (22:37 -0400)
1. E_STRICT error due to passing return of array_intersect() into reset() directly
2. Details in junit output can produce invalid UTF-8 and XML due to unescaped characters

run-tests.php

index 2a4698639f3d945e57dfc1e254cf23a88fc1e135..302167a6e5c5d3f5f4e4bddd7ec74c6f04b895dd 100755 (executable)
@@ -2668,12 +2668,15 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
        $time = null !== $time ? $time : junit_get_timer($file_name);
        junit_suite_record($suite, 'execution_time', $time);
 
+       $escaped_details = htmlspecialchars($details, 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";
 
        if (is_array($type)) {
                $output_type = $type[0] . 'ED';
-               $type = reset(array_intersect(array('XFAIL', 'FAIL'), $type));
+               $temp = array_intersect(array('XFAIL', 'FAIL'), $type);
+               $type = reset($temp);
        } else {
                $output_type = $type . 'ED';
        }
@@ -2688,10 +2691,10 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
                $JUNIT['files'][$file_name]['xml'] .= "<skipped>$message</skipped>\n";
        } elseif('FAIL' == $type) {
                junit_suite_record($suite, 'test_fail');
-               $JUNIT['files'][$file_name]['xml'] .= "<failure type='$output_type' message='$message'>$details</failure>\n";
+               $JUNIT['files'][$file_name]['xml'] .= "<failure type='$output_type' message='$message'>$escaped_details</failure>\n";
        } else {
                junit_suite_record($suite, 'test_error');
-               $JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$message'>$details</error>\n";
+               $JUNIT['files'][$file_name]['xml'] .= "<error type='$output_type' message='$message'>$escaped_details</error>\n";
        }
 
        $JUNIT['files'][$file_name]['xml'] .= "</testcase>\n";