diff --git a/npm-user-validate.js b/npm-user-validate.js index 9250ce3..ffd8791 100644 --- a/npm-user-validate.js +++ b/npm-user-validate.js @@ -11,6 +11,7 @@ var requirements = exports.requirements = { }, password: {}, email: { + length: 'Email length must be less then or equal to 254 characters long', valid: 'Email must be an email address' } } @@ -45,7 +46,10 @@ function username (un) { } function email (em) { - if (!em.match(/^.+@.+\..+$/)) { + if (em.length > 254) { + return new Error(requirements.email.length) + } + if (!em.match(/^[^@]+@.+\..+$/)) { return new Error(requirements.email.valid) } diff --git a/package.json b/package.json index 76214e7..ffcf1be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "npm-user-validate", - "version": "1.0.0", + "version": "1.0.1", "description": "User validations for npm", "main": "npm-user-validate.js", "devDependencies": { @@ -22,5 +22,8 @@ "registry" ], "author": "Robert Kowalski ", - "license": "BSD-2-Clause" + "license": "BSD-2-Clause", + "files": [ + "npm-user-validate.js" + ] } diff --git a/test/email.test.js b/test/email.test.js index c2e58ae..7cda76e 100644 --- a/test/email.test.js +++ b/test/email.test.js @@ -7,6 +7,13 @@ test('email misses an @', function (t) { t.end() }) +test('email is longer then 254 characters', function (t) { + var str = '@'.repeat(255) + var err = v(str) + t.type(err, 'object') + t.end() +}) + test('email misses a dot', function (t) { var err = v('name@domain') t.type(err, 'object')