fix(web(js)): improve validation of email addresses

Overwrite the AngularJS validation and transformation of email inputs in
order to support umlauts and eszett.
This commit is contained in:
Francis Lachapelle
2022-07-28 10:43:49 -04:00
parent 5e6ad77d4c
commit 67ccf748ed
9 changed files with 32 additions and 22 deletions

View File

@@ -199,7 +199,8 @@
<label>
<var:string label:value="Email Address"/>
</label>
<input type="email" ng-model="email.value"
<input type="text" ng-model="email.value"
ng-pattern="editor.emailRE"
sg-focus-on="email_{{$index}}"/>
</md-input-container>
</div>

View File

@@ -164,9 +164,10 @@
<md-input-container class="md-block"
ng-hide="$AccountDialogController.customFromIsReadonly()">
<label><var:string label:value="Reply To Email"/></label>
<input type="email"
<input type="text"
autocomplete="off"
ng-model="identity.replyTo"/>
ng-model="identity.replyTo"
ng-pattern="$AccountDialogController.emailRE"/>
</md-input-container>
<md-input-container
class="md-block md-flex"

View File

@@ -79,9 +79,10 @@
<var:string label:value="When I modify my calendar, send a mail to"/>
</md-checkbox>
<md-input-container flex-offset="5" md-no-float="md-no-float">
<input type="email"
<input type="text"
label:placeholder="Email Address"
ng-model="properties.calendar.notifiedUserOnPersonalModifications"
ng-pattern="properties.emailRE"
ng-required="properties.calendar.notifications.notifyUserOnPersonalModifications"
ng-disabled="!properties.calendar.notifications.notifyUserOnPersonalModifications"/>
</md-input-container>

View File

@@ -1,5 +1,7 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
String.emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([\u00C0-\u017Fa-z0-9]{1}[\u00C0-\u017Fa-z0-9\-]{0,62}[\u00C0-\u017Fa-z0-9]{1})|[\u00C0-\u017Fa-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/;
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
@@ -135,10 +137,13 @@ String.prototype.formatted = function() {
};
String.prototype.isValidEmail = function(strict) {
var emailRE = strict ?
/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i : /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i;
var result = emailRE.test(this);
return emailRE.test(this);
if (strict && result) {
result = emailRE.exec(this)[0] == this;
}
return result;
};
String.prototype.asCSSIdentifier = function() {

View File

@@ -11,16 +11,17 @@
function CardController($scope, $timeout, $window, $mdDialog, sgSettings, AddressBook, Card, Dialog, sgHotkeys, focus, $state, $stateParams, stateCard) {
var vm = this, hotkeys = [];
vm.card = stateCard;
this.card = stateCard;
vm.currentFolder = AddressBook.selectedFolder;
vm.allEmailTypes = Card.$EMAIL_TYPES;
vm.allTelTypes = Card.$TEL_TYPES;
vm.allUrlTypes = Card.$URL_TYPES;
vm.allAddressTypes = Card.$ADDRESS_TYPES;
vm.categories = {};
vm.userFilterResults = [];
vm.showRawSource = false;
this.currentFolder = AddressBook.selectedFolder;
this.allEmailTypes = Card.$EMAIL_TYPES;
this.allTelTypes = Card.$TEL_TYPES;
this.allUrlTypes = Card.$URL_TYPES;
this.allAddressTypes = Card.$ADDRESS_TYPES;
this.categories = {};
this.userFilterResults = [];
this.showRawSource = false;
this.emailRE = String.emailRE;
_registerHotkeys(hotkeys);

View File

@@ -279,7 +279,7 @@
if (angular.isString(this[type])) {
// The recipient is a string; try to extract the name
var emailRE = /<?(([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))/i;
var match = this[type].match(emailRE);
var match = this[type].match(String.emailRE);
if (match) {
address = this[type].substring(0, match.index);
address = address.replace(/^\"? *(.+?)\"? *$/, "$1");

View File

@@ -16,6 +16,7 @@
this.account = account;
this.accountId = accountId;
this.hostnameRE = usesSSO && accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
this.emailRE = String.emailRE;
this.addressesSearchText = '';
this.ckConfig = {
'autoGrow_minHeight': 70,

View File

@@ -294,12 +294,11 @@
destinationCalendar = Calendar.$get(this.component.destinationCalendar),
options = initOrganizer? { organizerCalendar: destinationCalendar } : {},
promises = [];
var emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i,
i, address;
var i, address;
if (partial) options.partial = partial;
function createCard(str) {
var match = str.match(emailRE),
var match = str.match(String.emailRE),
email = match[0],
name = str.replace(new RegExp(" *<?" + email + ">? *"), '');
vm.showAttendeesEditor |= initOrganizer;
@@ -333,7 +332,7 @@
card.charCodeAt(i) == 32 || // space
card.charCodeAt(i) == 44 || // ,
card.charCodeAt(i) == 59) && // ;
emailRE.test(address)) {
String.emailRE.test(address)) {
promises.push(createCard(address).then(addCard));
address = '';
}
@@ -341,7 +340,7 @@
address += card.charAt(i);
}
}
if (address && emailRE.test(address)) {
if (address && String.emailRE.test(address)) {
promises.push(createCard(address).then(addCard));
}
}

View File

@@ -245,6 +245,7 @@
function PropertiesDialogController($scope, $mdDialog, srcCalendar) {
var vm = this;
vm.emailRE = String.emailRE;
vm.calendar = new Calendar(srcCalendar.$omit());
vm.saveProperties = saveProperties;
vm.close = close;