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