Skip to content
Open
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
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ class S3Adapter {
}

const fileKey = `${this._bucketPrefix}${fileName}`;
// For presigned URLs, use the original unencoded filename to prevent double encoding
const presignedFileKey = `${this._bucketPrefix}${filename}`;

let presignedUrl = '';
if (this._presignedUrl) {
const params = { Bucket: this._bucket, Key: fileKey };
const params = { Bucket: this._bucket, Key: presignedFileKey };
const options = this._presignedUrlExpires ? { expiresIn: this._presignedUrlExpires } : {};

const command = new GetObjectCommand(params);
Expand Down
16 changes: 16 additions & 0 deletions spec/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,22 @@ describe('S3Adapter tests', () => {
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
});

it('should not double-encode special characters in presigned URLs', async () => {
delete options.baseUrl;
options.presignedUrl = true;
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);

// Test filename with special characters that need URL encoding
const specialFilename = 'doc[123].pdf';
const fileLocation = await s3.getFileLocation(testConfig, specialFilename);

// Should be encoded once (not double-encoded)
// %5B and %5D are correct encoding for [ and ]
// Double encoding would be %255B and %255D
expect(fileLocation).toContain('doc%5B123%5D.pdf');
expect(fileLocation).not.toContain('doc%255B123%255D.pdf');
});
});

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