From a0dc7da9b4e249d19acbb6399c47d56134e0b03f Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Wed, 28 Nov 2012 15:50:42 +1300 Subject: [PATCH] MDL-29835: filemanager - zero means zero, not unlimited The form_filemanager constructor was using empty() rather than !isset(), so overwrote maxfiles=0 with the default (-1). In addition, the JS UI treated 0 as unlimited - but the non-JS fallback UI treated it as zero. This would result in a file manager which allowed files to be chosen/uploaded, which would then vanish into the void when the backend saw that the maximum number of files was 0. --- lib/form/dndupload.js | 3 ++- lib/form/filemanager.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 1e68cc8faf2..68df5ac597d 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -537,7 +537,8 @@ M.form_dndupload.init = function(Y, options) { if (!overwrite) { this.currentfilecount++; } - if (this.options.maxfiles > 0 && this.currentfilecount > this.options.maxfiles) { + // The value for "unlimited files" is -1, so 0 should mean 0. + if (this.options.maxfiles >= 0 && this.currentfilecount > this.options.maxfiles) { // Too many files - abort entire upload. this.uploadqueue = []; this.renamequeue = []; diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index c67cfd922f3..77ee16903e5 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -332,7 +332,8 @@ class form_filemanager implements renderable { $defaults['defaultlicense'] = $CFG->sitedefaultlicense; } foreach ($defaults as $key=>$value) { - if (empty($options->$key)) { + // Using !isset() prevents us from overwriting falsey values with defaults (as empty() did). + if (!isset($options->$key)) { $options->$key = $value; } }