Skip to content

Commit

Permalink
MDL-73826 mod_lti: Fix for Windows/PHP8 with empty curl responses
Browse files Browse the repository at this point in the history
Sometimes (detected with Windows, when running @ GHA), both the
response and the error of a curl request to non-existing URL
returns the empty string.

In that case, we cannot call to DOMDocument::loadXML() because the
1st param cannot be empty. So here, whenever that happens, we are
throwing the moodle_exception earlier, instead of waiting for the
XML errors to be processed later.
  • Loading branch information
stronk7 committed Feb 11, 2022
1 parent 6994e82 commit e6aeab1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mod/lti/locallib.php
Expand Up @@ -4392,6 +4392,13 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
$curl = new curl();
$response = $curl->get($url);

// Got a completely empty response (real or error), cannot process this with
// DOMDocument::loadXML() because it errors with ValueError. So let's throw
// the moodle_exception before waiting to examine the errors later.
if (trim($response) === '') {
throw new moodle_exception('errorreadingfile', '', '', $url);
}

// TODO MDL-46023 Replace this code with a call to the new library.
$origerrors = libxml_use_internal_errors(true);
$origentity = lti_libxml_disable_entity_loader(true);
Expand Down

0 comments on commit e6aeab1

Please sign in to comment.