bug26614_libxml.phpt 2.2 KB

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