Skip to content

Commit

Permalink
Fix reject files when specifying the complete mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo authored and Saulis committed Jun 8, 2016
1 parent 492a42e commit c34ea2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions test/adding-files.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@
upload._addFiles([file]);
expect(upload.files.lentgh == 1);
});

it('should allow files with correct mime type', function() {
upload.accept = 'application/x-octet-stream';
upload._addFiles([file]);
expect(upload.files.lentgh == 1);
});

it('should allow wildcards', function() {
upload.accept = 'application/x-octet-stream';
upload._addFiles([file]);
expect(upload.files.lentgh == 1);
});
});

});
Expand Down
5 changes: 2 additions & 3 deletions vaadin-upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,9 @@
this.fire('file-reject', {file: file, error: this.i18n.error.fileIsTooBig});
return;
}
var mimeType = file.type ? file.type.match(/^[^\/]*\//)[0] : null;
var fileType = file.name.match(/\.[^\.]*$|$/)[0];
var fileExt = file.name.match(/\.[^\.]*$|$/)[0];
var re = new RegExp('^(' + this.accept.replace(/[, ]+/g, '|').replace('/*', '/.*') + ')$');
if (this.accept && !(re.test(mimeType) || re.test(fileType))) {
if (this.accept && !(re.test(file.type) || re.test(fileExt))) {
this.fire('file-reject', {file: file, error: this.i18n.error.incorrectFileType});
return;
}
Expand Down

0 comments on commit c34ea2e

Please sign in to comment.