From b93a6b3729b80c77e65ffeb135e457b47715ec76 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Tue, 24 Sep 2013 17:37:27 -0700 Subject: [PATCH] Fix non-ASCII contact matching; fix #6605 --- .../composer/contact-entry-completion.vala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client/composer/contact-entry-completion.vala b/src/client/composer/contact-entry-completion.vala index 4db3d9ab..5f49c119 100644 --- a/src/client/composer/contact-entry-completion.vala +++ b/src/client/composer/contact-entry-completion.vala @@ -113,21 +113,22 @@ public class ContactEntryCompletion : Gtk.EntryCompletion { if (addresses.size < 1) return empty_addresses; - int characters_seen_so_far = 0; + int bytes_seen_so_far = 0; current_address_index = addresses.size - 1; for (int i = 0; i < addresses.size; i++) { - int token_chars = addresses[i].char_count() + delimiter.char_count(); - if ((characters_seen_so_far + token_chars) > cursor_position) { + int cursor_offset = addresses[i].index_of_nth_char(cursor_position); + int token_bytes = addresses[i].length + delimiter.length; + if ((bytes_seen_so_far + token_bytes) > cursor_offset) { current_address_index = i; current_address_key = addresses[i] - .substring(0, cursor_position - characters_seen_so_far) + .substring(0, cursor_offset - bytes_seen_so_far) .strip().normalize().casefold(); current_address_remainder = addresses[i] - .substring(cursor_position - characters_seen_so_far).strip(); + .substring(cursor_offset - bytes_seen_so_far).strip(); break; } - characters_seen_so_far += token_chars; + bytes_seen_so_far += token_bytes; } return addresses; @@ -176,8 +177,9 @@ public class ContactEntryCompletion : Gtk.EntryCompletion { try { string escaped_needle = Regex.escape_string(needle.normalize()); Regex regex = new Regex("\\b" + escaped_needle, RegexCompileFlags.CASELESS); - if (regex.match(haystack)) { - highlighted_result = regex.replace_eval(haystack, -1, 0, 0, eval_callback); + string haystack_normalized = haystack.normalize(); + if (regex.match(haystack_normalized)) { + highlighted_result = regex.replace_eval(haystack_normalized, -1, 0, 0, eval_callback); matched = true; } } catch (RegexError err) {