diff --git a/source/image-handler/test/test-thumbor-mapping.js b/source/image-handler/test/test-thumbor-mapping.js index 0968fd3ea..fa5bfb889 100644 --- a/source/image-handler/test/test-thumbor-mapping.js +++ b/source/image-handler/test/test-thumbor-mapping.js @@ -30,12 +30,12 @@ describe('process()', function() { thumborMapping.process(event); // Assert const expectedResult = { - edits: { + edits: { + grayscale: true, resize: { width: 200, - height: 300 + height: 300, }, - grayscale: true } }; assert.deepEqual(thumborMapping.edits, expectedResult.edits); diff --git a/source/image-handler/thumbor-mapping.js b/source/image-handler/thumbor-mapping.js index dc9e8a76c..57705e0ce 100644 --- a/source/image-handler/thumbor-mapping.js +++ b/source/image-handler/thumbor-mapping.js @@ -29,26 +29,35 @@ class ThumborMapping { this.path = event.path; const edits = this.path.split('/'); const filetype = (this.path.split('.'))[(this.path.split('.')).length - 1]; + //Process the dimensions of the image + const dimPath = this.path.match(/[^\/]\d+x\d+/g); + if (dimPath) { + const dims = dimPath[0].split('x'); + // Set only if the dimensions provided are valid + if (isNaN(dims[0]) == false && isNaN(dims[1]) == false) { + this.edits.resize = {}; + // Assign dimenions from the first match only to avoid parsing dimension from image file names + this.edits.resize.width = Number(dims[0]); + this.edits.resize.height = Number(dims[1]); + + } + } // Parse the image path for (let i = 0; i < edits.length; i++) { const edit = edits[i]; if (edit === ('fit-in')) { - this.edits.resize = {}; + if (this.edits.resize === undefined) { + this.edits.resize = {}; + } this.sizingMethod = edit; - } - else if (edit.includes('x')) { - this.edits.resize = {}; - const dims = edit.split('x'); - this.edits.resize.width = Number(dims[0]); - this.edits.resize.height = Number(dims[1]); - } - if (edit.includes('filters:')) { + } + else if (edit.includes('filters:')) { this.mapFilter(edit, filetype); } } return this; } - + /** * Enables users to migrate their current image request model to the SIH solution, * without changing their legacy application code to accomodate new image requests.