Merge branch 'MDL-70896-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2021-03-18 00:34:05 +01:00
commit ac086dcf23
3 changed files with 43 additions and 9 deletions

View File

@ -117,11 +117,11 @@ function imscp_parse_structure($imscp, $context) {
*/
function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) {
$doc = new DOMDocument();
$oldentities = libxml_disable_entity_loader(true);
$oldentities = imscp_libxml_disable_entity_loader(true);
if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) {
return null;
}
libxml_disable_entity_loader($oldentities);
imscp_libxml_disable_entity_loader($oldentities);
// We put this fake URL as base in order to detect path changes caused by xml:base attributes.
$doc->documentURI = 'http://grrr/';
@ -221,11 +221,11 @@ function imscp_recursive_href($manifestfilename, $imscp, $context) {
}
$doc = new DOMDocument();
$oldentities = libxml_disable_entity_loader(true);
$oldentities = imscp_libxml_disable_entity_loader(true);
if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) {
return null;
}
libxml_disable_entity_loader($oldentities);
imscp_libxml_disable_entity_loader($oldentities);
$xmlresources = $doc->getElementsByTagName('resource');
foreach ($xmlresources as $res) {
@ -274,6 +274,23 @@ function imscp_recursive_item($xmlitem, $level, $resources) {
);
}
/**
* Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8
*
* Method was deprecated in PHP 8 and it shows deprecation message. However it is still
* required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it.
* @see https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation
*
* @param bool $value
* @return bool
*/
function imscp_libxml_disable_entity_loader(bool $value): bool {
if (PHP_VERSION_ID < 80000) {
return (bool)libxml_disable_entity_loader($value);
}
return true;
}
/**
* File browsing support class
*

View File

@ -4384,7 +4384,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
// TODO MDL-46023 Replace this code with a call to the new library.
$origerrors = libxml_use_internal_errors(true);
$origentity = libxml_disable_entity_loader(true);
$origentity = lti_libxml_disable_entity_loader(true);
libxml_clear_errors();
$document = new DOMDocument();
@ -4396,7 +4396,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
libxml_clear_errors();
libxml_use_internal_errors($origerrors);
libxml_disable_entity_loader($origentity);
lti_libxml_disable_entity_loader($origentity);
if (count($errors) > 0) {
$message = 'Failed to load cartridge.';
@ -4481,3 +4481,20 @@ function lti_new_access_token($typeid, $scopes) {
}
/**
* Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8
*
* Method was deprecated in PHP 8 and it shows deprecation message. However it is still
* required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it.
* @see https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation
*
* @param bool $value
* @return bool
*/
function lti_libxml_disable_entity_loader(bool $value): bool {
if (PHP_VERSION_ID < 80000) {
return (bool)libxml_disable_entity_loader($value);
}
return true;
}

View File

@ -70,13 +70,13 @@ if ($consumerkey === false) {
}
// TODO MDL-46023 Replace this code with a call to the new library.
$origentity = libxml_disable_entity_loader(true);
$origentity = lti_libxml_disable_entity_loader(true);
$xml = simplexml_load_string($rawbody);
if (!$xml) {
libxml_disable_entity_loader($origentity);
lti_libxml_disable_entity_loader($origentity);
throw new Exception('Invalid XML content');
}
libxml_disable_entity_loader($origentity);
lti_libxml_disable_entity_loader($origentity);
$body = $xml->imsx_POXBody;
foreach ($body->children() as $child) {