From f82de05f4ba4cde505ffff72b7562b5f01ba3fd1 Mon Sep 17 00:00:00 2001 From: s2 Date: Wed, 8 Apr 2020 18:19:54 +0200 Subject: [PATCH] throw exception if string is not selected length --- lib/secure-random-string.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/secure-random-string.js b/lib/secure-random-string.js index cc67b9c..398087b 100644 --- a/lib/secure-random-string.js +++ b/lib/secure-random-string.js @@ -31,6 +31,9 @@ function srs(options, cb) { } else { string = string.replace(/\//g, '_').replace(/\+/g, '-'); } + if (string.length < length) { + throw new Error(`Generated string is too short. Please catch this Error and try again.`); + } return string.substr(0, length); } };