From fa5630820c0422da00404ba078742fc2ed0a178b Mon Sep 17 00:00:00 2001 From: Georges Jamous Date: Sun, 12 Nov 2017 03:53:25 +0200 Subject: [PATCH] Update RestWrite.js --- src/RestWrite.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/RestWrite.js b/src/RestWrite.js index 424284d5ba..a7a47b3cbe 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -448,10 +448,18 @@ RestWrite.prototype._validateEmail = function() { if (!this.data.email || this.data.email.__op === 'Delete') { return Promise.resolve(); } - // Validate basic email address format - if (!this.data.email.match(/^.+@.+$/)) { + + // Validate basic email address format. + // Will strip spaces surrounding the string. Any space within the string will not pass. + if (!this.data.email.trim().match( /^[^\s@]+@[^\s@]+\.[^\s@]+$/ )) { return Promise.reject(new Parse.Error(Parse.Error.INVALID_EMAIL_ADDRESS, 'Email address format is invalid.')); } + + //Fixes issues where emails might be duplicated because of a space ' ' or case sensitivity. + if ( _this8.data.email ) { + _this8.data.email = _this8.data.email.split(' ').join('').toLowerCase(); + } + // Same problem for email as above for username return this.config.database.find( this.className,