better checks for file extensions

jpg allows jpeg
dots dont break extensions
v1.18.x
barisusakli 10 years ago
parent fbfb39f967
commit c98bd87334

@ -46,10 +46,6 @@ file.isFileTypeAllowed = function(path, allowedExtensions, callback) {
return callback(); return callback();
} }
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
return extension.trim();
});
var magic = new Magic(mmmagic.MAGIC_MIME_TYPE); var magic = new Magic(mmmagic.MAGIC_MIME_TYPE);
magic.detectFile(path, function(err, mimeType) { magic.detectFile(path, function(err, mimeType) {
if (err) { if (err) {
@ -72,6 +68,14 @@ file.allowedExtensions = function() {
return []; return [];
} }
allowedExtensions = allowedExtensions.split(','); allowedExtensions = allowedExtensions.split(',');
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
extension = extension.trim();
return extension.replace(/\./g, '');
});
if (allowedExtensions.indexOf('jpg') !== -1 && allowedExtensions.indexOf('jpeg') === -1) {
allowedExtensions.push('jpeg');
}
console.log(allowedExtensions)
return allowedExtensions; return allowedExtensions;
}; };

@ -140,7 +140,7 @@
</div> </div>
<strong>Topic Thumb Size</strong><br /> <input type="text" class="form-control" value="120" data-field="topicThumbSize"> <br /> <strong>Topic Thumb Size</strong><br /> <input type="text" class="form-control" value="120" data-field="topicThumbSize"> <br />
<strong>Allowed file types, (ie png, pdf, zip). Leave empty to allow all.</strong><br /> <input type="text" class="form-control" value="" data-field="allowedFileExtensions"><br /> <strong>Allowed file types, (ie png, jpg, pdf, zip). Leave empty to allow all.</strong><br /> <input type="text" class="form-control" value="" data-field="allowedFileExtensions"><br />
</form> </form>
</div> </div>

Loading…
Cancel
Save