Annotation of embedaddon/php/ext/xml/tests/bug26614.phpt, revision 1.1

1.1     ! misho       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 expat 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: 
        !            14: further investigation has shown that not only line count
        !            15: is skippet 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: 
        !            21: $xmls = array();
        !            22: 
        !            23: // Case 1: CDATA Sections
        !            24: $xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
        !            25: <data>
        !            26: <![CDATA[
        !            27: multi
        !            28: line 
        !            29: CDATA
        !            30: block
        !            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[
        !            38: multi
        !            39: line 
        !            40: CDATA
        !            41: block
        !            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[
        !            49: multi
        !            50: line 
        !            51: CDATA
        !            52: block
        !            53: ---
        !            54: </data>';
        !            55: 
        !            56: function 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: 
        !            63: function 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: 
        !            70: function characterData($parser, $data) {
        !            71:   // dummy 
        !            72: }
        !            73: 
        !            74: foreach ($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--
        !            85: CDATA
        !            86: <DATA> at line 2, col 0 (byte 45)
        !            87: </DATA> at line 9, col 0 (byte 90)
        !            88: Comment
        !            89: <DATA> at line 2, col 0 (byte 45)
        !            90: </DATA> at line 9, col 0 (byte 90)
        !            91: Text
        !            92: <DATA> at line 2, col 0 (byte 45)
        !            93: </DATA> at line 9, col 0 (byte 90)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>