From 28e7a80ebabae5c6d6bbf93d33911f99414583bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Fri, 21 Mar 2014 18:32:05 +0100 Subject: [PATCH] OP-01-011 Error suppression in UTF-8 decoding function (Medium). Add check for parameter type to decode_utf8. --- src/util.js | 3 +++ test/general/basic.js | 9 +++++++++ 2 files changed, 12 insertions(+) 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/); + }); + + }); + });