From: grodny at oneclick dot sk Operating system: Windows PHP version: 5.3CVS-2009-02-25 (snap) PHP Bug Type: XML related Bug description: xml_get_current_byte_index inside character data handler returns wrong offset
Description: ------------ Byte index returned by xml_get_current_byte_index() call in character data handler, points to different locations of XML source, based on character data being parsed. If parsed string passed as second argument to handler starts with ASCII non-white space character, byte index is offset to location before parsed string. If parsed string starts with white space, or UTF-8 character, it points after parsed string. To keep consistency with other handlers, it should return offset to location after parsed string, in all cases. Reproduce code: --------------- $xml = '<R><N>before</N><N>' .html_entity_decode('§', ENT_COMPAT, 'UTF-8') .'after</N><N> after</N>before </R>'; function cdata ($p, $cdata) { global $xml; $off = xml_get_current_byte_index($p); echo 'CDATA: "', htmlentities($cdata, ENT_COMPAT, 'UTF-8'), '"', PHP_EOL, 'AFTER-INDEX: "', htmlentities(substr($xml, $off), ENT_COMPAT, 'UTF-8'), '"', PHP_EOL; } $p = xml_parser_create('UTF-8'); xml_set_character_data_handler($p, 'cdata'); xml_parse($p, $xml, true); xml_parser_free($p); Expected result: ---------------- CDATA: "before" AFTER-INDEX: "</N><N>§after</N><N> after</N>before </R>" CDATA: "§after" AFTER-INDEX: "</N><N> after</N>before </R>" CDATA: " after" AFTER-INDEX: "</N>before </R>" CDATA: "before " AFTER-INDEX: "</R>" Actual result: -------------- CDATA: "before" AFTER-INDEX: "before</N><N>§after</N><N> after</N>before </R>" CDATA: "§after" AFTER-INDEX: "</N><N> after</N>before </R>" CDATA: " after" AFTER-INDEX: "</N>before </R>" CDATA: "before " AFTER-INDEX: "before </R>" -- Edit bug report at http://bugs.php.net/?id=47502&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47502&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47502&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47502&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47502&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47502&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47502&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47502&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47502&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47502&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47502&r=support Expected behavior: http://bugs.php.net/fix.php?id=47502&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47502&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47502&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47502&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47502&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47502&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47502&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47502&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47502&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47502&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47502&r=mysqlcfg