mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 06:46:02 +02:00
better checks for file extensions
jpg allows jpeg dots dont break extensions
This commit is contained in:
12
src/file.js
12
src/file.js
@@ -46,10 +46,6 @@ file.isFileTypeAllowed = function(path, allowedExtensions, callback) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
|
||||
return extension.trim();
|
||||
});
|
||||
|
||||
var magic = new Magic(mmmagic.MAGIC_MIME_TYPE);
|
||||
magic.detectFile(path, function(err, mimeType) {
|
||||
if (err) {
|
||||
@@ -72,6 +68,14 @@ file.allowedExtensions = function() {
|
||||
return [];
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user