Skip to content

Commit b93a143

Browse files
committed
chore: encodeURI is enough
1 parent 95f3e0d commit b93a143

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

src/storage/object/copy.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ export const copyFile = async (config, env, daCtx, sourceKey, details, isRename)
4646
return { $metadata: { httpStatusCode: 404 } };
4747
}
4848

49-
// URL-encode the key parts while preserving slashes for S3 folder structure
50-
const encodedKey = sourceKey
51-
.split('/')
52-
.map((segment) => encodeURIComponent(segment))
53-
.join('/');
54-
5549
const input = {
5650
Bucket: daCtx.bucket,
5751
Key: `${daCtx.org}/${Key}`,
58-
CopySource: `${daCtx.bucket}/${daCtx.org}/${encodedKey}`,
52+
CopySource: `${daCtx.bucket}/${daCtx.org}/${encodeURI(sourceKey)}`,
5953
ContentType: source?.contentType || 'application/octet-stream',
6054
};
6155

test/storage/object/copy.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ describe('Object copy', () => {
506506
// Test file with commas, equals signs, and spaces
507507
const resp1 = await copyFile({}, env, daCtx, 'mysrc/icon=gift-box, style=two-toned.svg', details, false);
508508
assert.strictEqual(resp1.constructor.name, 'CopyObjectCommand');
509-
assert.strictEqual(resp1.input.CopySource, 'root-bucket/myorg/mysrc/icon%3Dgift-box%2C%20style%3Dtwo-toned.svg');
509+
assert.strictEqual(resp1.input.CopySource, 'root-bucket/myorg/mysrc/icon=gift-box,%20style=two-toned.svg');
510510
assert.strictEqual(resp1.input.Key, 'myorg/mydst/icon=gift-box, style=two-toned.svg');
511511

512512
// Test file with spaces

0 commit comments

Comments
 (0)