浏览代码

Fix mime type checking bug (#2004)

* fix for mimetype issue #1988

* core: disregard mime parameters

Co-authored-by: Renée Kooi <renee@kooi.me>
Mohammed Shahim 5 年之前
父节点
当前提交
6bef0a0314
共有 2 个文件被更改,包括 14 次插入7 次删除
  1. 1 1
      packages/@uppy/core/src/index.js
  2. 13 6
      packages/@uppy/core/src/index.test.js

+ 1 - 1
packages/@uppy/core/src/index.js

@@ -438,7 +438,7 @@ class Uppy {
         // is this is a mime-type
         if (type.indexOf('/') > -1) {
           if (!file.type) return false
-          return match(file.type, type)
+          return match(file.type.replace(/;.*?$/, ''), type)
         }
 
         // otherwise this is likely an extension

+ 13 - 6
packages/@uppy/core/src/index.test.js

@@ -631,20 +631,27 @@ describe('src/Core', () => {
     it('should not allow a file that does not meet the restrictions', () => {
       const core = new Core({
         restrictions: {
-          allowedFileTypes: ['image/gif']
+          allowedFileTypes: ['image/gif', 'video/webm']
         }
       })
-      try {
+
+      expect(() => {
         core.addFile({
           source: 'jest',
           name: 'foo.jpg',
           type: 'image/jpeg',
           data: new File([sampleImage], { type: 'image/jpeg' })
         })
-        throw new Error('File was allowed through')
-      } catch (err) {
-        expect(err.message).toEqual('You can only upload: image/gif')
-      }
+      }).toThrow('You can only upload: image/gif, video/webm')
+
+      expect(() => {
+        core.addFile({
+          source: 'jest',
+          name: 'foo.webm',
+          type: 'video/webm; codecs="vp8, opus"',
+          data: new File([sampleImage], { type: 'video/webm; codecs="vp8, opus"' })
+        })
+      }).not.toThrow()
     })
 
     it('should not allow a dupicate file, a file with the same id', () => {