public static function prepareString($string) { return preg_replace('([\\x00-\\x04\\x0b\\x0c\\x0e-\\x1f\\x7f])e', 'sprintf( "&#x%02x;", ord( "\\1" ) )', htmlspecialchars(self::convertToUtf8($string), ENT_COMPAT, 'UTF-8')); }
/** * @dataProvider charProvider */ public function testPrepareString($char) { $e = null; $escapedString = PHPUnit_Util_XML::prepareString($char); $xml = "<?xml version='1.0' encoding='UTF-8' ?><tag>{$escapedString}</tag>"; $dom = new DomDocument('1.0', 'UTF-8'); try { $dom->loadXML($xml); } catch (Exception $e) { } $this->assertNull($e, sprintf('PHPUnit_Util_XML::prepareString("\\x%02x") should not crash DomDocument', ord($char))); }