Skip to content

Commit 974a3eb

Browse files
committed
Add test for double encoding
1 parent 2c922b8 commit 974a3eb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spec/test.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,22 @@ describe('S3Adapter tests', () => {
638638
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
639639
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
640640
});
641+
642+
it('should not double-encode special characters in presigned URLs', async () => {
643+
delete options.baseUrl;
644+
options.presignedUrl = true;
645+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
646+
647+
// Test filename with special characters that need URL encoding
648+
const specialFilename = 'doc[123].pdf';
649+
const fileLocation = await s3.getFileLocation(testConfig, specialFilename);
650+
651+
// Should be encoded once (not double-encoded)
652+
// %5B and %5D are correct encoding for [ and ]
653+
// Double encoding would be %255B and %255D
654+
expect(fileLocation).toContain('doc%5B123%5D.pdf');
655+
expect(fileLocation).not.toContain('doc%255B123%255D.pdf');
656+
});
641657
});
642658

643659
describe('getFileLocation with async baseUrl', () => {

0 commit comments

Comments
 (0)