Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix can not put file when PutExtra.fname contains double quotes #421

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading