From fb893bec36d298324d031f6d59c5884b76f20f26 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 11 Jul 2016 17:10:13 -0400 Subject: [PATCH] fix(GUI): ignore casing when checking an image extension validity (#568) Currently, we take the image extension casing into account when determining if the extension is a recognised one (e.g: `img`, `iso`, etc). This causes an "Invalid image" error to be thrown when selecting an image with an uppercase extension, like `UBUNTU.ISO`. Change-Type: patch Changelog-Entry: Don't throw an "Invalid image" error if the extension is not in lowercase. Fixes: https://github.com/resin-io/etcher/issues/567 Signed-off-by: Juan Cruz Viotti --- lib/gui/models/supported-formats.js | 2 +- tests/gui/models/supported-formats.spec.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/gui/models/supported-formats.js b/lib/gui/models/supported-formats.js index 7f512fad..d730f6eb 100644 --- a/lib/gui/models/supported-formats.js +++ b/lib/gui/models/supported-formats.js @@ -115,7 +115,7 @@ SupportedFormats.service('SupportedFormatsModel', function() { * } */ this.isSupportedImage = (image) => { - const extension = path.extname(image).slice(1); + const extension = path.extname(image).slice(1).toLowerCase(); if (_.some([ _.includes(this.getNonCompressedExtensions(), extension), diff --git a/tests/gui/models/supported-formats.spec.js b/tests/gui/models/supported-formats.spec.js index 26b99875..fd69db32 100644 --- a/tests/gui/models/supported-formats.spec.js +++ b/tests/gui/models/supported-formats.spec.js @@ -78,6 +78,13 @@ describe('Browser: SupportedFormats', function() { m.chai.expect(isSupported).to.be.true; }); + it('should ignore casing when determining extension validity', function() { + const nonCompressedExtension = _.first(SupportedFormatsModel.getNonCompressedExtensions()); + const imagePath = '/path/to/foo.' + nonCompressedExtension.toUpperCase(); + const isSupported = SupportedFormatsModel.isSupportedImage(imagePath); + m.chai.expect(isSupported).to.be.true; + }); + it('should not consider an extension before a non compressed extension', function() { const nonCompressedExtension = _.first(SupportedFormatsModel.getNonCompressedExtensions()); const imagePath = '/path/to/foo.1234.' + nonCompressedExtension;