bug26614_libxml.phpt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --TEST--
  2. Bug #26614 (CDATA sections skipped on line count)
  3. --EXTENSIONS--
  4. xml
  5. --SKIPIF--
  6. <?php
  7. if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. this test works fine with Expat but fails with libxml
  13. which we now use as default
  14. further investigation has shown that not only line count
  15. is skipped on CDATA sections but that libxml does also
  16. show different column numbers and byte positions depending
  17. on context and in opposition to what one would expect to
  18. see and what good old Expat reported just fine ...
  19. */
  20. $xmls = array();
  21. // Case 1: CDATA Sections
  22. $xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
  23. <data>
  24. <![CDATA[
  25. multi
  26. line
  27. CDATA
  28. block
  29. ]]>
  30. </data>';
  31. // Case 2: replace some characters so that we get comments instead
  32. $xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
  33. <data>
  34. <!-- ATA[
  35. multi
  36. line
  37. CDATA
  38. block
  39. -->
  40. </data>';
  41. // Case 3: replace even more characters so that only textual data is left
  42. $xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
  43. <data>
  44. -!-- ATA[
  45. multi
  46. line
  47. CDATA
  48. block
  49. ---
  50. </data>';
  51. function startElement($parser, $name, $attrs) {
  52. printf("<$name> at line %d, col %d (byte %d)\n",
  53. xml_get_current_line_number($parser),
  54. xml_get_current_column_number($parser),
  55. xml_get_current_byte_index($parser));
  56. }
  57. function endElement($parser, $name) {
  58. printf("</$name> at line %d, col %d (byte %d)\n",
  59. xml_get_current_line_number($parser),
  60. xml_get_current_column_number($parser),
  61. xml_get_current_byte_index($parser));
  62. }
  63. function characterData($parser, $data) {
  64. // dummy
  65. }
  66. foreach ($xmls as $desc => $xml) {
  67. echo "$desc\n";
  68. $xml_parser = xml_parser_create();
  69. xml_set_element_handler($xml_parser, "startElement", "endElement");
  70. xml_set_character_data_handler($xml_parser, "characterData");
  71. if (!xml_parse($xml_parser, $xml, true))
  72. echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
  73. xml_parser_free($xml_parser);
  74. }
  75. ?>
  76. --EXPECTF--
  77. CDATA
  78. <DATA> at line 2, col %d (byte 9)
  79. </DATA> at line 9, col %d (byte 55)
  80. Comment
  81. <DATA> at line 2, col %d (byte 9)
  82. </DATA> at line 9, col %d (byte 55)
  83. Text
  84. <DATA> at line 2, col %d (byte 9)
  85. </DATA> at line 9, col %d (byte 55)