File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff 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 - z A - Z 0 - 9 . ! # $ % & ' * + \/ = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? (?: \. [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 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 ( ) {
You can’t perform that action at this time.
0 commit comments