Conversation
|
TypeScript definitions update - DefinitelyTyped/DefinitelyTyped#65578 |
|
@starnayuta |
|
@LinusU Are there any blockers for merging this PR? Can we merge it? |
|
@UlisesGascon, maybe you could assist with this PR? |
|
Would be nice to merge this. |
|
It has been over a year, please kindly merge it. |
|
Hi @Doc999tor, you can add tests to verify the behavior |
it just works, get another task to add tests for this, the current behavior isnt even well tested anyways |
|
@bjohansebas This change is simply "pass this option down to busboy", so a test for it should basically just be "busbuy has received the argument", right? |
|
Well, I really have no idea if it's actually possible to test this, but since it fixes something in the package, ideally, we should have a test for it. |
|
@Doc999tor Could you please do a rebase? And an example of tests could be: describe('UTF-8 filenames', 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, defParamCharset: 'utf-8' })
done()
})
})
afterEach(function (done) {
rimraf(uploadDir, done)
})
it('should handle UTF-8 filenames', function (done) {
var req = new stream.PassThrough()
var boundary = 'AaB03x'
var body = [
'--' + boundary,
'Content-Disposition: form-data; name="small0"; filename="ÖoϪ.dat"',
'Content-Type: text/plain',
'',
'test with UTF-8 filename',
'--' + boundary + '--'
].join('\r\n')
req.headers = {
'content-type': 'multipart/form-data; boundary=' + boundary,
'content-length': body.length
}
req.end(body)
upload.single('small0')(req, null, function (err) {
assert.ifError(err)
assert.strictEqual(req.file.originalname, 'ÖoϪ.dat')
assert.strictEqual(req.file.fieldname, 'small0')
done()
})
})
}) |
|
I will do, thanks for the test example |
|
Great, if you do it I can close #1327 |
|
Just a remainder
Non-ASCII characters (like Ö or Ϫ) can be misinterpreted if the stream isn’t properly encoded. To avoid ambiguity and ensure cross-platform compatibility, use the filename* syntax with UTF-8 percent-encoding as recommended in RFC 5987, Section 3.2.2. Also, see this test case in the Multer codebase before making changes to how filenames are handled. |
@ShubhamOulkar Although, if I understand correctly, RFC 7578, Section 4.2 forbids the usage of this syntax. |
|
Why is this not merged yet? I appreciate the desire for good test coverage but this is very clearly broken, and it's not a very complex change, just passing through a parameter to busboy. |
|
@bjohansebas rebased and added tests, sorry for taking too long 🙏
|
|
Interesting coincidence, I had just completed working on a new PR with your changes and a few tests 😆 |
|
|
||
| this.limits = options.limits | ||
| this.preservePath = options.preservePath | ||
| this.defParamCharset = options.defParamCharset || 'latin1' |
There was a problem hiding this comment.
This default shouldn't need to be passed explicitly, busboy uses latin1 anyway when the defParamCharset passed is undefined.
There was a problem hiding this comment.
Yes, I know - I added it in case something will change in busboy default settings, multer will still behave consistently
@LinusU @bjohansebas @UlisesGascon what do you think? I can change it if it's unnecessary precaution
There was a problem hiding this comment.
It feels like the default should be utf-8 but that would also technically be a breaking API change for multer. Thank you for maintaining consistency. :)
|
@UlisesGascon @unc0ded @bjohansebas @LinusU Can one of you review the PR? |
I think busboy won't change the default without a major version bump anyway, so setting a default here may be overkill. But I leave it upto the maintainers here to take a call on that. |
|
Non-english parts of the world are in pain for ~3 years thanks to this. I just love littering my codebase with code like |
|
Please merge and publish this. |
|
It should be merged! |
|
Is there any to-do's left here? |
|
This is so important!! please merge it! 🙏 |
This PR adds support of busboy's
defParamCharsetoption for supporting UTF8 characters in request headers such asfilenameDefault:
'latin1'for backward compatibilityNot required
Resolves #1104, #1194
Example of usage: