From 109f8a5d2052dbf31839dd7ca66dfcf2650d823d Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Wed, 14 Dec 2016 12:38:01 -0800 Subject: [PATCH 1/3] don't allow leading spaces in user id --- src/openpgp.js | 5 ++++- src/util.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openpgp.js b/src/openpgp.js index 0a5cacf3..02f69e2a 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -391,7 +391,10 @@ function formatUserIds(options) { if (!util.isString(id.name) || (id.email && !util.isEmailAddress(id.email))) { throw new Error('Invalid user id format'); } - return id.name + ' <' + id.email + '>'; + if (id.name) { + id.name += ' '; + } + return id.name + '<' + id.email + '>'; }); return options; } diff --git a/src/util.js b/src/util.js index 32f22445..b329d84b 100644 --- a/src/util.js +++ b/src/util.js @@ -51,7 +51,7 @@ export default { if (!this.isString(data)) { return false; } - return / $/.test(data); + return /$/.test(data); }, /** From d058523e9ed583742701eb3d0acfa235924b9da7 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Thu, 15 Dec 2016 10:01:50 -0800 Subject: [PATCH 2/3] clearer syntax --- src/openpgp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openpgp.js b/src/openpgp.js index 02f69e2a..50167cd4 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -391,7 +391,7 @@ function formatUserIds(options) { if (!util.isString(id.name) || (id.email && !util.isEmailAddress(id.email))) { throw new Error('Invalid user id format'); } - if (id.name) { + if (id.name.length > 0) { id.name += ' '; } return id.name + '<' + id.email + '>'; From d65d62926492964fee5886fcf9688b0be15905ae Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Thu, 15 Dec 2016 10:39:29 -0800 Subject: [PATCH 3/3] trim name --- src/openpgp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openpgp.js b/src/openpgp.js index 50167cd4..658a52be 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -391,6 +391,7 @@ function formatUserIds(options) { if (!util.isString(id.name) || (id.email && !util.isEmailAddress(id.email))) { throw new Error('Invalid user id format'); } + id.name = id.name.trim(); if (id.name.length > 0) { id.name += ' '; }