-
Bug
-
Resolution: Fixed
-
Minor
-
3.8.5, 3.9.3, 3.10, 4.0
-
MOODLE_310_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
-
MOODLE_38_STABLE, MOODLE_39_STABLE
-
MDL-69758-master -
We saw errors like this in the server logs:
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /srv/learn2.open.ac.uk/www/html/course/externallib.php on line 324
This is after the following code:
$getcontentfunction = $cm->modname.'_export_contents';
|
if (function_exists($getcontentfunction)) {
|
$contents = $getcontentfunction($cm, $baseurl);
|
The _export_contents function is expected to return an array. If it does not, you get these warnings.
The cause turned out to be in url_export_contents:
$isurl = clean_param($fullurl, PARAM_URL);
|
if (empty($isurl)) {
|
return null;
|
}
|
And this was happening because the URL was set to:
http://www.open.ac.uk/libraryservices//beingdigital/
Note the double slash - sketchy, but it works. (The URL also works with only a single slash there.)
From the mobile app (where this webservice is called), clicking on the link doesn't work - it does nothing.
If you change the URL to a single slash then it doesn't cause this error.
There is clearly (imo) a bug in url_export_contents - instead of returning null, it should return an empty array if there's an error. I looked at the other _export_contents functions and didn't find any other examples of the same problem.
However, is it correct that clean_param returns empty in this case? I had a quick look at the URI RFC and don't think it forbids empty path segments... I'm going to leave that for a separate issue if we need to fix it... Likewise, I wonder if mod_url should validate the URL against the same function on the settings form? Maybe hard because of placeholders or something?