From fc6ccf70ddd0954edf3a97899c28e3ed95c14ce9 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 8 Jun 2016 15:49:55 -0400 Subject: [PATCH] Prevent selection of invalid images (#462) The user might attempt to select an invalid image by dropping on the first step, which would cause Etcher to blindly select it, possibly causing errors later on the process. This PR makes use of the list of supported extensions provided by `SupportedFormatsModel` and prevents the selection if necessary, logging an event that might help us determine which unsupported image types users try to burn most often. Signed-off-by: Juan Cruz Viotti --- lib/gui/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/gui/app.js b/lib/gui/app.js index 858c86e3..e4a8568d 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -21,6 +21,7 @@ 'use strict'; var angular = require('angular'); +const path = require('path'); const _ = require('lodash'); const app = angular.module('Etcher', [ @@ -188,6 +189,13 @@ app.controller('AppController', function( document.querySelector('body').style.display = 'initial'; this.selectImage = function(image) { + const extension = path.extname(image.path).slice(1); + + if (!_.includes(SupportedFormatsModel.getAllExtensions(), extension)) { + AnalyticsService.logEvent('Invalid image', image); + return; + } + self.selection.setImage(image); AnalyticsService.logEvent('Select image', image); };