From 33c19542afab25c18be55a1f58b9b8cc18a3b2cf Mon Sep 17 00:00:00 2001 From: larabr Date: Mon, 15 May 2023 16:21:51 +0200 Subject: [PATCH] Allow email addresses with trailing numbers in domain (#1642) Domains such as .com09 are valid (see RFC1123) --- src/util.js | 2 +- test/general/key.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index f250dcd9..73f08fb2 100644 --- a/src/util.js +++ b/src/util.js @@ -424,7 +424,7 @@ const util = { if (!util.isString(data)) { return false; } - const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+([a-zA-Z]{2,}|xn--[a-zA-Z\-0-9]+)))$/; + const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+([a-zA-Z]{2,}[0-9]*|xn--[a-zA-Z\-0-9]+)))$/; return re.test(data); }, diff --git a/test/general/key.js b/test/general/key.js index 508af7e0..8b294959 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -2367,6 +2367,19 @@ function versionSpecificTests() { }); }); + it('Generate key - single userID (special email format)', async function() { + const userID = { name: 'test', email: 'test1@com.com09', comment: '' }; + const opt = { userIDs: userID }; + const { privateKey: armoredKey } = await openpgp.generateKey(opt); + // test also serialisation and parsing + const key = await openpgp.readKey({ armoredKey }); + expect(key.users.length).to.equal(1); + expect(key.users[0].userID.userID).to.equal('test '); + expect(key.users[0].userID.name).to.equal(userID.name); + expect(key.users[0].userID.email).to.equal(userID.email); + expect(key.users[0].userID.comment).to.equal(userID.comment); + }); + it('Generate key - setting date to the past', function() { const past = new Date(0); const opt = {