Factor out basic email check (#10244)

This commit is contained in:
Michael Weimann 2023-02-28 10:39:35 +01:00 committed by GitHub
parent f40d15388c
commit 2c7dfb5401
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 2 deletions

View file

@ -657,7 +657,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
this.setState({ tryingIdentityServer: true });
return;
}
if (term.indexOf("@") > 0 && Email.looksValid(term) && SettingsStore.getValue(UIFeature.IdentityServer)) {
if (Email.looksValid(term) && SettingsStore.getValue(UIFeature.IdentityServer)) {
// Start off by suggesting the plain email while we try and resolve it
// to a real account.
this.setState({
@ -796,7 +796,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
continue;
}
if (address.indexOf("@") > 0 && Email.looksValid(address)) {
if (Email.looksValid(address)) {
toAdd.push(new ThreepidMember(address));
continue;
}

View file

@ -1,5 +1,6 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -22,5 +23,8 @@ const EMAIL_ADDRESS_REGEX = new RegExp(
);
export function looksValid(email: string): boolean {
// short circuit regex with this basic check
if (email.indexOf("@") < 1) return false;
return EMAIL_ADDRESS_REGEX.test(email);
}