Skip to content

Commit 2f18b92

Browse files
authored
fix can not put file when PutExtra.fname contains double quotes (#421)
1 parent bfb1584 commit 2f18b92

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## CHANGE LOG
2+
## 7.10.1
3+
- 对象存储,修复无法上传带有英文双引号的文件
4+
25
## 7.10.0
36
- 对象存储,上传支持双活
47
- 对象存储,上传回调支持 Promise 风格

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qiniu",
3-
"version": "7.10.0",
3+
"version": "7.10.1",
44
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
55
"main": "index.js",
66
"directories": {

qiniu/storage/form.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,15 @@ function createMultipartForm (uploadToken, key, fsStream, putExtra) {
250250
if (key != null) {
251251
postForm.field('key', key);
252252
}
253+
// fix the bug of formstream
254+
// https://html.spec.whatwg.org/#multipart-form-data
255+
const escapeFname = putExtra.fname.replace(/"/g, '%22')
256+
.replace(/\r/g, '%0D')
257+
.replace(/\n/g, '%0A');
253258
postForm.stream(
254259
'file',
255260
fsStream,
256-
putExtra.fname,
261+
escapeFname,
257262
putExtra.mimeType
258263
);
259264

test/form_up.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ describe('test form up', function () {
160160
});
161161
});
162162

163+
describe('test form up#putFile with double quotes', function () {
164+
it('test form up#putFile with double quotes', function () {
165+
const key = 'storage_putFile_"test"' + Math.ceil(1000 * Math.random());
166+
const putExtra = new qiniu.form_up.PutExtra();
167+
putExtra.fname = key;
168+
return formUploader.putFile(uploadToken, key, testFilePath_2,
169+
putExtra,
170+
function (
171+
respErr,
172+
respBody) {
173+
// console.log(respBody);
174+
should.not.exist(respErr);
175+
respBody.should.have.keys('key', 'hash');
176+
keysToDelete.push(respBody.key);
177+
});
178+
});
179+
});
180+
163181
// eslint-disable-next-line no-undef
164182
describe('test form up#putFileWithoutKey', function () {
165183
// eslint-disable-next-line no-undef

0 commit comments

Comments
 (0)