diff --git a/js/invitees.js b/js/invitees.js index 802268c..b986f14 100644 --- a/js/invitees.js +++ b/js/invitees.js @@ -13,7 +13,9 @@ 'use strict'; var DEBOUNCE_MS = 250; - var SEPARATOR = /[;,]/; + /* Must match the server's attendee parsing: whitespace, comma and + * semicolon all separate entries. */ + var SEPARATOR = /[\s;,]+/; var input = document.getElementById('atocal-attendees'); @@ -59,7 +61,7 @@ } function commit(email) { - var parts = input.value.split(/([;,])/); + var parts = input.value.split(/([\s;,]+)/); parts.pop(); var prefix = parts.join('').replace(/\s+$/, ''); diff --git a/tests/js/invitees.test.mjs b/tests/js/invitees.test.mjs index b6734f3..bc5ea3b 100644 --- a/tests/js/invitees.test.mjs +++ b/tests/js/invitees.test.mjs @@ -125,4 +125,29 @@ describe('invitee suggestions', () => { expect(list.hidden).toBe(true); expect(list.children).toHaveLength(0); }); + + it('searches only the last whitespace-separated fragment', async () => { + fetch.mockReturnValue(response([BOB])); + + type('alice@example.com bo'); + await settle(); + + expect(fetch).toHaveBeenCalledWith( + SEARCH_URL + '?query=bo', + expect.objectContaining({ headers: { Accept: 'application/json' } }) + ); + }); + + it('keeps whitespace-separated entries when picking a contact', async () => { + fetch.mockReturnValue(response([BOB])); + + type('alice@example.com bo'); + await settle(); + + list.querySelector('button').dispatchEvent( + new MouseEvent('mousedown', { bubbles: true, cancelable: true }) + ); + + expect(input.value).toBe('alice@example.com bob@example.com, '); + }); });