From a27763312d57ece9b3bdcaf8958a0c5b492e1d4c Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Apr 2018 09:18:06 -0600 Subject: [PATCH] Allow spaces in file names --- lib/utils.js | 2 +- tests/utils.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 409feac..8f18c4a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -121,7 +121,7 @@ exports.getFileName = function(key, options) { // reserved characters in Windows filenames. // See: https://en.wikipedia.org/wiki/Filename#Reserved%5Fcharacters%5Fand%5Fwords const escapedFileName = encodeURIComponent(keyFileName) - .replace(/\*/g, '-'); + .replace(/\*/g, '-').replace(/%20/g, ' '); return path.join(options.dataPath || exports.getDataPath(), escapedFileName); }; diff --git a/tests/utils.spec.js b/tests/utils.spec.js index 8876618..90f01a6 100644 --- a/tests/utils.spec.js +++ b/tests/utils.spec.js @@ -137,6 +137,11 @@ describe('Utils', function() { m.chai.expect(path.basename(fileName)).to.equal('john6638%40gmail-dot-com.json'); }); + it('should allow spaces in file names', function() { + const fileName = utils.getFileName('foo bar'); + m.chai.expect(path.basename(fileName)).to.equal('foo bar.json'); + }); + it('should react to user data path changes', function() { const newUserDataPath = path.join(utils.getDataPath(), 'foo' , 'bar'); utils.setDataPath(newUserDataPath);