diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index e8eb084c7a..e89e77f3ca 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -197,12 +197,19 @@ var twin2 = { email: 'twin2@zulip.com', }; +var gael = { + full_name: 'Gaël Twin', + user_id: 107, + email: 'twin3@zulip.com', +}; + global.people.add_in_realm(hamlet); global.people.add_in_realm(othello); global.people.add_in_realm(cordelia); global.people.add_in_realm(lear); global.people.add_in_realm(twin1); global.people.add_in_realm(twin2); +global.people.add_in_realm(gael); global.people.add(deactivated_user); var hamletcharacters = { @@ -529,7 +536,7 @@ run_test('initialize', () => { // This should match the users added at the beginning of this test file. var actual_value = options.source(); var expected_value = [hamlet, othello, cordelia, lear, - twin1, twin2, hamletcharacters, backend]; + twin1, twin2, gael, hamletcharacters, backend]; assert.deepEqual(actual_value, expected_value); // Even though the items passed to .highlighter() are the full @@ -560,6 +567,15 @@ run_test('initialize', () => { assert.equal(options.matcher(othello), false); assert.equal(options.matcher(cordelia), false); + options.query = 'gael'; + assert.equal(options.matcher(gael), true); + + options.query = 'Gaël'; + assert.equal(options.matcher(gael), true); + + options.query = 'gaël'; + assert.equal(options.matcher(gael), true); + // Don't make suggestions if the last name only has whitespaces // (we're between typing names). options.query = 'othello@zulip.com, '; diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 1f2b547245..328ff4be69 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -50,6 +50,8 @@ function query_matches_language(query, lang) { } function query_matches_string(query, source_str, split_char) { + source_str = people.remove_diacritics(source_str); + query = people.remove_diacritics(query); // When `abc ` with a space at the end is typed in a // contenteditable widget such as the composebox PM section, the // space at the end was a `no break-space (U+00A0)` instead of diff --git a/static/js/people.js b/static/js/people.js index bb413cd260..93b135119f 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -739,7 +739,7 @@ exports.incr_recipient_count = function (user_id) { // Diacritic removal from: // https://stackoverflow.com/questions/18236208/perform-a-find-match-with-javascript-ignoring-special-language-characters-acce -function remove_diacritics(s) { +exports.remove_diacritics = function (s) { if (/^[a-z]+$/.test(s)) { return s; } @@ -751,7 +751,7 @@ function remove_diacritics(s) { .replace(/[úùüû]/g, "u") .replace(/[ç]/g, "c") .replace(/[ñ]/g, "n"); -} +}; exports.person_matches_query = function (user, query) { var email = user.email.toLowerCase(); @@ -770,7 +770,7 @@ exports.person_matches_query = function (user, query) { return _.any(names, function (name) { if (is_ascii) { // Only ignore diacritics if the query is plain ascii - name = remove_diacritics(name); + name = exports.remove_diacritics(name); } if (name.indexOf(termlet) === 0) { return true;