xref: /PHP-8.1/ext/xmlreader/tests/bug71805.phpt (revision 74859783)
1--TEST--
2XMLReader: Bug #71805 XML files can generate UTF-8 error even if they are UTF-8
3--EXTENSIONS--
4xmlreader
5--FILE--
6<?php
7
8TestXML(__DIR__ . DIRECTORY_SEPARATOR . 'XMLReaderGood_bug71805.xml');
9TestXML(__DIR__ . DIRECTORY_SEPARATOR . 'XMLReaderBad_bug71805.xml');
10
11function TestXML($file) {
12    $XR = new XMLReader;
13    $XR->open($file, null, LIBXML_NOBLANKS);
14
15    while (($lastRead = $XR->read()) && ($XR->name !== 'records'));
16    while (($lastRead = $XR->read()) && ($XR->name !== 'record'));
17    while ($lastRead) {
18        $xml = $XR->readOuterXML();
19        if ($xml === '') {
20            $err = '';
21            if ($e = libxml_get_last_error()) { $err = $e->message.' (line: '.$e->line.')'; }
22            $XR->close();
23            echo $file.' : Problem with file'.($err ? ' — '.$err : '').'.';
24            echo "\n";
25            return;
26        }
27        while (($lastRead = $XR->next()) && ($XR->name !== 'record'));
28    }
29    $XR->close();
30    echo $file.' : Good!';
31    echo "\n";
32    return;
33}
34?>
35--EXPECTF--
36%sXMLReaderGood_bug71805.xml : Good!
37%sXMLReaderBad_bug71805.xml : Good!
38