diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 24ba80bd5de3..a6f28f0fbadb 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -784,10 +784,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL, if (ret == NULL) { if (resource == NULL) { if (ID == NULL) { - ID = "NULL"; + php_libxml_ctx_error(context, + "Failed to load external entity because the resolver function returned null\n"); + } else { + php_libxml_ctx_error(context, + "Failed to load external entity \"%s\"\n", ID); } - php_libxml_ctx_error(context, - "Failed to load external entity \"%s\"\n", ID); } else { /* we got the resource in the form of a string; open it */ ret = xmlNewInputFromFile(context, resource); diff --git a/ext/libxml/tests/null_returned_by_resolver.phpt b/ext/libxml/tests/null_returned_by_resolver.phpt new file mode 100644 index 000000000000..8fdfbc6dc8b4 --- /dev/null +++ b/ext/libxml/tests/null_returned_by_resolver.phpt @@ -0,0 +1,32 @@ +--TEST-- +null returned by resolver function +--EXTENSIONS-- +libxml +dom +--FILE-- +loadHTMLFile("foobar"); + +?> +--EXPECTF-- +NULL +string(6) "foobar" +array(4) { + ["directory"]=> + NULL + ["intSubName"]=> + NULL + ["extSubURI"]=> + NULL + ["extSubSystem"]=> + NULL +} + +Warning: DOMDocument::loadHTMLFile(): Failed to load external entity because the resolver function returned null in %s on line %d