diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e2c77a..6a42cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## CHANGE LOG +## 7.10.1 +- 对象存储,修复无法上传带有英文双引号的文件 + ## 7.10.0 - 对象存储,上传支持双活 - 对象存储,上传回调支持 Promise 风格 diff --git a/package.json b/package.json index 6da8dd2..01b22d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qiniu", - "version": "7.10.0", + "version": "7.10.1", "description": "Node wrapper for Qiniu Resource (Cloud) Storage API", "main": "index.js", "directories": { diff --git a/qiniu/storage/form.js b/qiniu/storage/form.js index bbfa83d..2ef4cdb 100644 --- a/qiniu/storage/form.js +++ b/qiniu/storage/form.js @@ -250,10 +250,15 @@ function createMultipartForm (uploadToken, key, fsStream, putExtra) { if (key != null) { postForm.field('key', key); } + // fix the bug of formstream + // https://html.spec.whatwg.org/#multipart-form-data + const escapeFname = putExtra.fname.replace(/"/g, '%22') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A'); postForm.stream( 'file', fsStream, - putExtra.fname, + escapeFname, putExtra.mimeType ); diff --git a/test/form_up.test.js b/test/form_up.test.js index e25d476..3b6b5b4 100644 --- a/test/form_up.test.js +++ b/test/form_up.test.js @@ -160,6 +160,24 @@ describe('test form up', function () { }); }); + describe('test form up#putFile with double quotes', function () { + it('test form up#putFile with double quotes', function () { + const key = 'storage_putFile_"test"' + Math.ceil(1000 * Math.random()); + const putExtra = new qiniu.form_up.PutExtra(); + putExtra.fname = key; + return formUploader.putFile(uploadToken, key, testFilePath_2, + putExtra, + function ( + respErr, + respBody) { + // console.log(respBody); + should.not.exist(respErr); + respBody.should.have.keys('key', 'hash'); + keysToDelete.push(respBody.key); + }); + }); + }); + // eslint-disable-next-line no-undef describe('test form up#putFileWithoutKey', function () { // eslint-disable-next-line no-undef