Skip to content

Commit

Permalink
MDL-29835: filemanager - zero means zero, not unlimited
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pauln committed Jan 8, 2013
1 parent 9da506c commit a0dc7da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/form/dndupload.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ M.form_dndupload.init = function(Y, options) {
if (!overwrite) { if (!overwrite) {
this.currentfilecount++; 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. // Too many files - abort entire upload.
this.uploadqueue = []; this.uploadqueue = [];
this.renamequeue = []; this.renamequeue = [];
Expand Down
3 changes: 2 additions & 1 deletion lib/form/filemanager.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ public function __construct(stdClass $options) {
$defaults['defaultlicense'] = $CFG->sitedefaultlicense; $defaults['defaultlicense'] = $CFG->sitedefaultlicense;
} }
foreach ($defaults as $key=>$value) { 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; $options->$key = $value;
} }
} }
Expand Down

0 comments on commit a0dc7da

Please sign in to comment.