1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
--TEST--
libxml_set_external_entity_loader() variation: restore original handler; returning NULL
--EXTENSIONS--
dom
--CLEAN--
<?php
@unlink(__DIR__ . "/foobar.dtd");
?>
--FILE--
<?php
chdir(__DIR__);
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "foobar.dtd">
<foo>bar</foo>
XML;
$dtd = <<<DTD
<!ELEMENT foo (#PCDATA)>
DTD;
libxml_set_external_entity_loader(
function ($public, $system, $context) {
var_dump($public,$system);
return null;
}
);
$dd = new DOMDocument;
$r = $dd->loadXML($xml);
var_dump($dd->validate());
libxml_set_external_entity_loader(NULL);
file_put_contents(__DIR__ . "/foobar.dtd", $dtd);
var_dump($dd->validate());
echo "Done.\n";
?>
--EXPECTF--
string(10) "-//FOO/BAR"
string(%d) "%sfoobar.dtd"
Warning: DOMDocument::validate(): Failed to load external entity "-//FOO/BAR" in %s on line %d
Warning: DOMDocument::validate(): Could not load the external subset "foobar.dtd" in %s on line %d
bool(false)
bool(true)
Done.
|