From 7fa41781619467df01d126abfdafeca6d06596b5 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 4 Aug 2016 11:02:20 -0400 Subject: [PATCH] minifix(GUI): don't call shell.openExternal if resource is undefined (#622) This PR fixes an uncaught error being thrown when `OSOpenExternalService.open()` is called with an undefined value. Signed-off-by: Juan Cruz Viotti --- lib/gui/os/open-external/services/open-external.js | 6 +++++- tests/gui/os/open-external.spec.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/gui/os/open-external/services/open-external.js b/lib/gui/os/open-external/services/open-external.js index 1b9f5e92..915fc888 100644 --- a/lib/gui/os/open-external/services/open-external.js +++ b/lib/gui/os/open-external/services/open-external.js @@ -30,6 +30,10 @@ module.exports = function() { * @example * OSOpenExternalService.open('https://www.google.com'); */ - this.open = electron.shell.openExternal; + this.open = (url) => { + if (url) { + electron.shell.openExternal(url); + } + }; }; diff --git a/tests/gui/os/open-external.spec.js b/tests/gui/os/open-external.spec.js index ef793590..dc173db8 100644 --- a/tests/gui/os/open-external.spec.js +++ b/tests/gui/os/open-external.spec.js @@ -52,6 +52,15 @@ describe('Browser: OSOpenExternal', function() { shellExternalStub.restore(); }); + it('should not call Electron shell.openExternal if the attribute value is not defined', function() { + const shellExternalStub = m.sinon.stub(electron.shell, 'openExternal'); + const element = $compile('Resin.io')($rootScope); + element.triggerHandler('click'); + $rootScope.$digest(); + m.chai.expect(shellExternalStub).to.not.have.been.called; + shellExternalStub.restore(); + }); + }); });