7 Jul 2012 16:41
[PHP-DEV] Run-tests.php JUnit format issue
Anthony Ferrara <ircmaxell <at> gmail.com>
2012-07-07 14:41:58 GMT
2012-07-07 14:41:58 GMT
Hey all, I've run into an issue with run-tests.php with the junit format. The XML that it generates can be invalid because of invalid UTF-8 characters and invalid XML characters. This means that trying to parse it using something like Jenkins gives a huge stack-trace because of invalid XML. I've been digging through how to fix it, and I think I've come up with a solution. But I'm not too happy with it, so I'd like some feedback. https://github.com/php/php-src/blob/master/run-tests.php#L2096 Right now, the diff for a failed test is just injected in cdata tags, and stuck unencoded in the result XML. For tests that are testing invalid UTF-8 bytes (or other character sets), that diff can contain bad byte sequences. $diff = empty($diff) ? '' : "<![CDATA[\n " . preg_replace('/\e/', '<esc>', $diff) . "\n]]>"; What I'm proposing is to escape all non-UTF8 and non-XML safe bytes with their value wrapped by <>. So chr(0xFF) (which is invalid in UTF8) would become <xFF> Now, to implement it is a bit more interesting. I've come up with a single regex that will do it: $diff = preg_replace_callback( '/( [\x0-\x8] # Control Characters | [\xB-\xC] # Invalid XML Characters | [\xE-\x19] # Invalid XML Characters(Continue reading)
RSS Feed