From cc4ab53887d2bb90642afe04616c6351c146ab60 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 25 Mar 2021 00:31:57 +0100 Subject: [PATCH] throw an error if encode input is not a buffer --- lib/urlsafe-base64.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/urlsafe-base64.js b/lib/urlsafe-base64.js index 7f26afa..78d4430 100644 --- a/lib/urlsafe-base64.js +++ b/lib/urlsafe-base64.js @@ -29,6 +29,7 @@ exports.version = '1.0.0'; */ exports.encode = function encode(buffer) { + if (!Buffer.isBuffer(buffer)) throw new TypeError('The input should be a buffer.') return buffer.toString('base64') .replace(/\+/g, '-') // Convert '+' to '-' @@ -74,4 +75,4 @@ exports.validate = function validate(base64) { return /^[A-Za-z0-9\-_]+$/.test(base64); -}; \ No newline at end of file +};