diff --git a/src/util.js b/src/util.js index c3f90e36..6edd68de 100644 --- a/src/util.js +++ b/src/util.js @@ -142,6 +142,9 @@ module.exports = { * @return {String} A native javascript string */ decode_utf8: function (utf8) { + if (typeof utf8 !== 'string') { + throw new Error('Parameter "utf8" is not of type string'); + } try { return decodeURIComponent(escape(utf8)); } catch (e) { diff --git a/test/general/basic.js b/test/general/basic.js index 26c140f0..7c090dea 100644 --- a/test/general/basic.js +++ b/test/general/basic.js @@ -328,4 +328,13 @@ describe('Basic', function() { }); }); + describe("Misc.", function() { + + it('util.decode_utf8 throws error if invalid parameter type', function () { + var test = openpgp.util.decode_utf8.bind(null, {chameleon: true}); + expect(test).to.throw(Error, /Parameter "utf8" is not of type string/); + }); + + }); + });