fix: Handle spaces in CC/BCC email lists (#6788)
When the CC field is generated in the UI, the email values are joined together with ", " but when they are parsed, we currently split by just ",". This causes an error on the backend and on the frontend. It seems reasonable to update the code to allow whitespace in the input and to split by `\s*,\s` and also to trim leading and trailing whitespace from the CC list. --------- Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -2,6 +2,6 @@ import emailValidator from 'vuelidate/lib/validators/email';
|
||||
|
||||
export const validEmailsByComma = value => {
|
||||
if (!value.length) return true;
|
||||
const emails = value.split(',');
|
||||
const emails = value.replace(/\s+/g, '').split(',');
|
||||
return emails.every(email => emailValidator(email));
|
||||
};
|
||||
|
||||
@@ -10,4 +10,7 @@ describe('#validEmailsByComma', () => {
|
||||
it('returns false when one of the email passed is invalid', () => {
|
||||
expect(validEmailsByComma('ni@njan.com,pova.da')).toEqual(false);
|
||||
});
|
||||
it('strips spaces between emails before validating', () => {
|
||||
expect(validEmailsByComma('1@test.com , 2@test.com')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user