Skip to content

Commit

Permalink
fix can not put file when PutExtra.fname contains double quotes (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Nov 21, 2023
1 parent bfb1584 commit 2f18b92
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## CHANGE LOG
## 7.10.1
- 对象存储,修复无法上传带有英文双引号的文件

## 7.10.0
- 对象存储,上传支持双活
- 对象存储,上传回调支持 Promise 风格
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion qiniu/storage/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
18 changes: 18 additions & 0 deletions test/form_up.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f18b92

Please sign in to comment.