Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support object key with characters need to be URI encoded #311

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion source/image-handler/image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ImageRequest {
if (requestType === "Default") {
// Decode the image request and return the image key
const decoded = this.decodeRequest(event);
return decoded.key;
return decodeURIComponent(decoded.key);
}

if (requestType === "Thumbor" || requestType === "Custom") {
Expand Down
35 changes: 35 additions & 0 deletions source/image-handler/test/image-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,41 @@ describe('setup()', function() {
expect(imageRequest).toEqual(expectedResult);
});
});
describe('010/defaultImageRequest/WithUriEncodedKey', function() {
it('Should pass when a default image request is provided and populate the ImageRequest object with the proper values and a URI encoded key', async function() {
// Arrange
const event = {
path : '/eyJidWNrZXQiOiJ2YWxpZEJ1Y2tldCIsImtleSI6IiVFNCVCOCVBRCVFNiU5NiU4NyIsImVkaXRzIjp7ImdyYXlzY2FsZSI6dHJ1ZX0sIm91dHB1dEZvcm1hdCI6ImpwZWcifQ=='
}
process.env = {
SOURCE_BUCKETS : "validBucket, validBucket2"
}
// Mock
mockAws.getObject.mockImplementationOnce(() => {
return {
promise() {
return Promise.resolve({ Body: Buffer.from('SampleImageContent\n') });
}
};
});
// Act
const imageRequest = new ImageRequest(s3, secretsManager);
await imageRequest.setup(event);
const expectedResult = {
requestType: 'Default',
bucket: 'validBucket',
key: '中文',
edits: { grayscale: true },
outputFormat: 'jpeg',
originalImage: Buffer.from('SampleImageContent\n'),
CacheControl: 'max-age=31536000,public',
ContentType: 'image/jpeg'
};
// Assert
expect(mockAws.getObject).toHaveBeenCalledWith({ Bucket: 'validBucket', Key: '中文' });
expect(imageRequest).toEqual(expectedResult);
});
});
});
// ----------------------------------------------------------------------------
// getOriginalImage()
Expand Down