From 645d64b940f9f6aad54562ef0958253c2af199f0 Mon Sep 17 00:00:00 2001 From: s2 Date: Thu, 27 Aug 2015 23:37:05 +0200 Subject: [PATCH] remove useless urlsafe: false option --- README.md | 9 +++------ lib/secure-random-string.js | 5 +---- tests.js | 17 ++--------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 51208d5..0f2a4f8 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,16 @@ srs(function(err, sr) { ``` -### Options: length, urlsafe +### Options: length Optionally, you can specify a 'length' option to specify a length. -When 'urlsafe' is true (the default), potential `+` and `/` characters are replaced respectively with `-` and `_`. -This is a valid [base64url](https://en.wikipedia.org/wiki/Base64) string. - ```javascript // sync -var result = srs({length: 256, urlsafe:true}); +var result = srs({length: 256}); // async -srs({length: 256, urlsafe:true}, function(err, sr) { +srs({length: 256}, function(err, sr) { console.log(sr); }); ``` diff --git a/lib/secure-random-string.js b/lib/secure-random-string.js index 08003d0..972e5f9 100644 --- a/lib/secure-random-string.js +++ b/lib/secure-random-string.js @@ -7,7 +7,6 @@ function srs(options, cb) { } else { options = options || {}; } - options.urlsafe = typeof(options.urlsafe) === 'boolean' ? options.urlsafe : true; var length = options['length'] || 32; @@ -27,9 +26,7 @@ function srs(options, cb) { function _finish (buf) { var string = buf.toString('base64'); - if (options.urlsafe) { - string = string.replace(/\//g,'_').replace(/\+/g,'-'); - } + string = string.replace(/\//g,'_').replace(/\+/g,'-'); return string.substr(0, length); } diff --git a/tests.js b/tests.js index 2947601..630ba62 100644 --- a/tests.js +++ b/tests.js @@ -50,28 +50,15 @@ srs({length: 256}, function(err, sr) { ); }); -srs({length: 256}, function(err, sr) { - test('generate a urlsafe random string 256 chars long', - sr.length, - 256 - ); -}); - // sync tests test('generate a random string 32 chars long (sync)', srs().length, 32); test('generate a random string 1 chars long (sync)', srs({length:1}).length, 1); test('generate a random string 256 chars long (sync)', srs({length:256}).length, 256); -test('generate a urlsafe random string 256 chars long (sync)', srs({length:256}).length, 256); -//when generating, the default should be urlsafe + //in 2000 chars there should be at least one substitution -test('check that the random string is urlsafe by default', (function() { +test('check that the random string is urlsafe', (function() { var s = srs({length: 2000}); return s.indexOf('+') + s.indexOf('/') === -2; })(), true); - -test('check that the useless urlsafe: false option works', (function() { - var s = srs({length: 2000, urlsafe: false}); - return s.indexOf('_') + s.indexOf('-') === -2; -})(), true);