Skip to content

Commit 06c0798

Browse files
committed
fix: test email address with regex
1 parent b21cbe4 commit 06c0798

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cryptify-front-end/src/EncryptPanel.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ export default class EncryptPanel extends React.Component<
148148
}
149149

150150
onChangeRecipient(ev: React.ChangeEvent<HTMLInputElement>) {
151+
// See: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
152+
const regex =
153+
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
154+
const stripped = ev.target.value.toLowerCase().replace(/ /g, "");
151155
this.setState({
152-
recipient: ev.target.value.toLowerCase().replace(/ /g, ""),
153-
recipientValid: ev.target.form?.checkValidity() ?? false,
156+
recipient: stripped,
157+
recipientValid: regex.test(stripped),
154158
});
155159
}
156160

@@ -386,12 +390,13 @@ export default class EncryptPanel extends React.Component<
386390
.map((f) => f.size)
387391
.reduce((a, b) => a + b, 0);
388392

389-
return (
393+
const canEncrypt =
390394
totalSize < MAX_UPLOAD_SIZE &&
391395
this.state.recipient.length > 0 &&
392396
this.state.recipientValid &&
393-
this.state.files.length > 0
394-
);
397+
this.state.files.length > 0;
398+
399+
return canEncrypt;
395400
}
396401

397402
renderfilesField() {

0 commit comments

Comments
 (0)