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