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

fixed a bug where base64 encoding containing slash will fail #194

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
7 changes: 3 additions & 4 deletions source/image-handler/image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ class ImageRequest {
decodeRequest(event) {
const path = event["path"];
if (path !== undefined) {
const splitPath = path.split("/");
const encoded = splitPath[splitPath.length - 1];
const toBuffer = Buffer.from(encoded, 'base64');
const strippedPath = path.charAt(0) === '/' ? path.substr(1, path.length) : path;
const toBuffer = Buffer.from(strippedPath, 'base64');
try {
// To support European characters, 'ascii' was removed.
return JSON.parse(toBuffer.toString());
Expand Down Expand Up @@ -300,4 +299,4 @@ class ImageRequest {
}

// Exports
module.exports = ImageRequest;
module.exports = ImageRequest;
14 changes: 14 additions & 0 deletions source/image-handler/test/test-image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ describe('setup()', function() {
})
});
});
describe('005/encodingWithSlashRequest', function () {
it(`should read image requests with base64 encoding having slash`, function () {
const event = {
path : 'eyJidWNrZXQiOiJlbGFzdGljYmVhbnN0YWxrLXVzLWVhc3QtMi0wNjY3ODQ4ODU1MTgiLCJrZXkiOiJlbnYtcHJvZC9nY2MvbGFuZGluZ3BhZ2UvMV81N19TbGltTl9MaWZ0LUNvcnNldC1Gb3ItTWVuLVNOQVAvYXR0YWNobWVudHMvZmZjMWYxNjAtYmQzOC00MWU4LThiYWQtZTNhMTljYzYxZGQzX1/Ys9mE2YrZhSDZhNmK2YHYqiAoMikuanBnIiwiZWRpdHMiOnsicmVzaXplIjp7IndpZHRoIjo0ODAsImZpdCI6ImNvdmVyIn19fQ=='
}
// Act
const imageRequest = new ImageRequest();
const result = imageRequest.parseImageKey(event, 'Default');
// Assert
const expectedResult = 'env-prod/gcc/landingpage/1_57_SlimN_Lift-Corset-For-Men-SNAP/attachments/ffc1f160-bd38-41e8-8bad-e3a19cc61dd3__سليم ليفت (2).jpg';
assert.deepEqual(result, expectedResult);

})
});
});
// ----------------------------------------------------------------------------
// getOriginalImage()
Expand Down