-
Bug
-
Resolution: Fixed
-
Minor
-
2.3.7, 2.4.5, 2.5, 2.6
-
MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
-
MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
-
MDL-40258_master -
I discovered a bug in the way that the "accepted_types" option of the file picker is handled. When passing in several different extensions and mime-types in the array file_get_grouptype() in lib/filelib.php returns an numerically indexed array of extensions. Those are passed in js_init_call(), which json_encodes it and includes in the page on output.
When the array has consecutive indices starting at 0 (e.g. array(0 => 'jpg', 1 => 'png', 2 => 'svg') it gets encoded as an Array in JavaScript (e.g. ['jpg', 'png', 'svg']) and when the filepicker code turns that into the accepted_types parameter for the ajax call to the repository it works great there is no error.
When the array has non-consecutive indices (e.g. array(0 => 'jpg', 1 => 'png', 9 => 'svg') it gets encoded as an JavaScript Object instead (e.g.
{0: 'jpg', 1: 'png', 9: 'svg'}which in turn gets turned into the string "[object Object]" when the filepicker code trys to turn it into the accepted_types parameter for the ajax call to the repository.