From 297fb2771e3a042d7608a1ec23089d619873403e Mon Sep 17 00:00:00 2001 From: Georges Jamous Date: Sun, 12 Nov 2017 04:20:26 +0200 Subject: [PATCH 1/2] 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..bfc43832de 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 ( this.data.email ) { + this.data.email = this.data.email.split(' ').join('').toLowerCase(); + } + // Same problem for email as above for username return this.config.database.find( this.className, From 2650838846e74f6da6db0ad89e9e29f34833d991 Mon Sep 17 00:00:00 2001 From: Georges Jamous Date: Mon, 13 Nov 2017 13:05:03 +0200 Subject: [PATCH 2/2] Update RestWrite.js --- src/RestWrite.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/RestWrite.js b/src/RestWrite.js index bfc43832de..019b4b62c2 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -450,15 +450,13 @@ RestWrite.prototype._validateEmail = function() { } // 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@]+$/ )) { + // Will strip spaces surrounding the string. If any space within the string, will not pass. + if (!this.data.email.trim().match( /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ )) { 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 ( this.data.email ) { - this.data.email = this.data.email.split(' ').join('').toLowerCase(); - } + this.data.email = this.data.email.split(' ').join('').toLowerCase(); // Same problem for email as above for username return this.config.database.find(