Skip to content

Commit e1cb721

Browse files
committed
Improve warning when returning null from the resolver set by libxml_set_external_entity_loader
Fixes GH-11952. Closes GH-12022.
1 parent 3e0e7e3 commit e1cb721

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PHP NEWS
77
. Introduced Zend guard recursion protection to fix __debugInfo issue.
88
(Jakub Zelenka)
99

10+
- DOM:
11+
. Fixed GH-11952 (Confusing warning when blocking entity loading via
12+
libxml_set_external_entity_loader). (nielsdos)
13+
1014
- Standard:
1115
. Added $before_needle argument to strrchr(). (HypeMC)
1216

ext/libxml/libxml.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
784784
if (ret == NULL) {
785785
if (resource == NULL) {
786786
if (ID == NULL) {
787-
ID = "NULL";
787+
php_libxml_ctx_error(context,
788+
"Failed to load external entity because the resolver function returned null\n");
789+
} else {
790+
php_libxml_ctx_error(context,
791+
"Failed to load external entity \"%s\"\n", ID);
788792
}
789-
php_libxml_ctx_error(context,
790-
"Failed to load external entity \"%s\"\n", ID);
791793
} else {
792794
/* we got the resource in the form of a string; open it */
793795
ret = xmlNewInputFromFile(context, resource);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
null returned by resolver function
3+
--EXTENSIONS--
4+
libxml
5+
dom
6+
--FILE--
7+
<?php
8+
9+
libxml_set_external_entity_loader(function ($public_id, $system_id, $context) {
10+
var_dump($public_id, $system_id, $context);
11+
return null;
12+
});
13+
14+
$doc = new DOMDocument();
15+
$doc->loadHTMLFile("foobar");
16+
17+
?>
18+
--EXPECTF--
19+
NULL
20+
string(6) "foobar"
21+
array(4) {
22+
["directory"]=>
23+
NULL
24+
["intSubName"]=>
25+
NULL
26+
["extSubURI"]=>
27+
NULL
28+
["extSubSystem"]=>
29+
NULL
30+
}
31+
32+
Warning: DOMDocument::loadHTMLFile(): Failed to load external entity because the resolver function returned null in %s on line %d

0 commit comments

Comments
 (0)