|
| 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 | +if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11'); |
| 9 | +?> |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | +/* |
| 13 | +this test works fine with Expat but fails with libxml |
| 14 | +which we now use as default |
| 15 | +
|
| 16 | +further investigation has shown that not only line count |
| 17 | +is skipped on CDATA sections but that libxml does also |
| 18 | +show different column numbers and byte positions depending |
| 19 | +on context and in opposition to what one would expect to |
| 20 | +see 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[ |
| 29 | +multi |
| 30 | +line |
| 31 | +CDATA |
| 32 | +block |
| 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[ |
| 40 | +multi |
| 41 | +line |
| 42 | +CDATA |
| 43 | +block |
| 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[ |
| 51 | +multi |
| 52 | +line |
| 53 | +CDATA |
| 54 | +block |
| 55 | +--- |
| 56 | +</data>'; |
| 57 | + |
| 58 | +function 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 | + |
| 65 | +function 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 | + |
| 72 | +function characterData($parser, $data) { |
| 73 | + // dummy |
| 74 | +} |
| 75 | + |
| 76 | +foreach ($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-- |
| 87 | +CDATA |
| 88 | +<DATA> at line 2, col %d (byte 50) |
| 89 | +</DATA> at line 9, col %d (byte 96) |
| 90 | +Comment |
| 91 | +<DATA> at line 2, col %d (byte 50) |
| 92 | +</DATA> at line 9, col %d (byte 96) |
| 93 | +Text |
| 94 | +<DATA> at line 2, col %d (byte 50) |
| 95 | +</DATA> at line 9, col %d (byte 96) |
0 commit comments