OP-01-011 Error suppression in UTF-8 decoding function (Medium). Add check for parameter type to decode_utf8.

This commit is contained in:
Thomas Oberndörfer 2014-03-21 18:32:05 +01:00
parent 3f626f4bfb
commit 28e7a80eba
2 changed files with 12 additions and 0 deletions

View File

@ -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) {

View File

@ -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/);
});
});
});