forked from expressjs/multer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicode.js
56 lines (43 loc) · 1.31 KB
/
unicode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-env mocha */
var assert = require('assert')
var path = require('path')
var util = require('./_util')
var multer = require('../')
var temp = require('fs-temp')
var rimraf = require('rimraf')
var FormData = require('form-data')
describe('Unicode', function () {
var uploadDir, upload
beforeEach(function (done) {
temp.mkdir(function (err, path) {
if (err) return done(err)
var storage = multer.diskStorage({
destination: path,
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
uploadDir = path
upload = multer({ storage: storage })
done()
})
})
afterEach(function (done) {
rimraf(uploadDir, done)
})
it('should handle unicode filenames', function (done) {
var form = new FormData()
var parser = upload.single('small0')
var filename = '\ud83d\udca9.dat'
form.append('small0', util.file('small0.dat'), { filename: filename })
util.submitForm(parser, form, function (err, req) {
assert.ifError(err)
assert.equal(path.basename(req.file.path), filename)
assert.equal(req.file.originalname, filename)
assert.equal(req.file.fieldname, 'small0')
assert.equal(req.file.size, 1778)
assert.equal(util.fileSize(req.file.path), 1778)
done()
})
})
})