xref: /PHP-7.3/ext/xmlreader/tests/bug71805.phpt (revision 53511513)
1--TEST--
2XMLReader: Bug #71805 XML files can generate UTF-8 error even if they are UTF-8
3--SKIPIF--
4<?php if (!extension_loaded("xmlreader")) print "skip"; ?>
5--FILE--
6<?php
7
8TestXML(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'XMLReaderGood_bug71805.xml');
9TestXML(dirname(__FILE__) . 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===DONE===
36--EXPECTF--
37%sXMLReaderGood_bug71805.xml : Good!
38%sXMLReaderBad_bug71805.xml : Good!
39===DONE===
40