Skip to content

Commit

Permalink
fix: should use encodeURIComponent insteadof encodeURI in copy api (#914
Browse files Browse the repository at this point in the history
)
  • Loading branch information
beajer authored Dec 25, 2020
1 parent 3775dc4 commit 9dceb70
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/common/object/copyObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ proto._getSourceName = function _getSourceName(sourceName, bucketName) {

_checkBucketName(bucketName);

sourceName = encodeURI(sourceName);
sourceName = encodeURIComponent(sourceName);

sourceName = `/${bucketName}/${sourceName}`;
return sourceName;
Expand Down
11 changes: 11 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@ describe('browser', () => {
info = await store.head(originname);
assert.equal(info.res.headers['cache-control'], 'max-age=0, s-maxage=86400');
});

it('should copy object with special characters such as ;,/?:@&=+$#', async () => {
const sourceName = `${prefix}ali-sdk/oss/copy-a;,/?:@&=+$#b.js`;
const fileContent = Array(1024 * 1024)
.fill('a')
.join('');
const file = new File([fileContent], sourceName);
await store.put(sourceName, file);
await store.copy(`${prefix}ali-sdk/oss/copy-a.js`, sourceName);
await store.copy(`${prefix}ali-sdk/oss/copy-a+b.js`, sourceName);
});
});

describe('signatureUrl()', () => {
Expand Down
20 changes: 13 additions & 7 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,14 @@ describe('test/object.test.js', () => {
assert.equal(info.status, 200);
});

it('should copy object with special characters such as ;,/?:@&=+$#', async () => {
const sourceName = `${prefix}ali-sdk/oss/copy-a;,/?:@&=+$#b.js`;
const tempFile = await utils.createTempFile('t', 1024 * 1024);
await store.put(sourceName, tempFile);
await store.copy(`${prefix}ali-sdk/oss/copy-a.js`, sourceName);
await store.copy(`${prefix}ali-sdk/oss/copy-a+b.js`, sourceName);
});

it('should use copy to change exists object headers', async () => {
const originname = `${prefix}ali-sdk/oss/copy-new-3.js`;
let result = await store.copy(originname, name);
Expand Down Expand Up @@ -1997,13 +2005,11 @@ describe('test/object.test.js', () => {
let keyCount = 0;
do {
// eslint-disable-next-line no-await-in-loop
const result = await store.listV2(
{
prefix: listPrefix,
'max-keys': 2,
'continuation-token': nextContinuationToken,
},
);
const result = await store.listV2({
prefix: listPrefix,
'max-keys': 2,
'continuation-token': nextContinuationToken
});
keyCount += result.keyCount;
nextContinuationToken = result.nextContinuationToken;
} while (nextContinuationToken);
Expand Down

0 comments on commit 9dceb70

Please sign in to comment.