I'm attaching a quilt patch that applies to version 0.5.0-0.1 with the
two commits from the upstream repo that solve the issue.

I've tried to build it: it does and it seems to be working fine on my
armhf board.

I'm not attaching a full debdiff because as far as I understand it
upstream is only waiting for confirmation from Jack Henschel that the
code is also working for him before closing the issue, and then it would
be available in the next upstream release, which I expect is probably
worth waiting for (at least for a while) at this stage, since it's going
to end up in buster anyway.

I did build on a machine with an UTF-8 locale, however.
-- 
Elena ``of Valhalla''
Index: profanity-0.5.0/src/common.c
===================================================================
--- profanity-0.5.0.orig/src/common.c	2016-09-15 23:53:43.000000000 +0200
+++ profanity-0.5.0/src/common.c	2017-05-29 22:21:35.722237804 +0200
@@ -509,13 +509,25 @@
         return *result;
     }
 
-    if (g_str_has_prefix(&haystack[offset], needle)) {
+    gchar *haystack_curr = g_utf8_offset_to_pointer(haystack, offset);
+    if (g_str_has_prefix(haystack_curr, needle)) {
         if (whole_word) {
-            char *prev = g_utf8_prev_char(&haystack[offset]);
-            char *next = g_utf8_next_char(&haystack[offset] + strlen(needle) - 1);
-            gunichar prevu = g_utf8_get_char(prev);
-            gunichar nextu = g_utf8_get_char(next);
-            if (!g_unichar_isalnum(prevu) && !g_unichar_isalnum(nextu)) {
+            gchar *needle_last_ch = g_utf8_offset_to_pointer(needle, g_utf8_strlen(needle, -1)- 1);
+            int needle_last_ch_len = mblen(needle_last_ch, MB_CUR_MAX);
+
+            gunichar before = NULL;
+            gchar *haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr);
+            if (haystack_before_ch) {
+                before = g_utf8_get_char(haystack_before_ch);
+            }
+
+            gunichar after = NULL;
+            gchar *haystack_after_ch = g_utf8_find_next_char(haystack_curr + strlen(needle) - needle_last_ch_len, NULL);
+            if (haystack_after_ch) {
+                after = g_utf8_get_char(haystack_after_ch);
+            }
+
+            if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) {
                 *result = g_slist_append(*result, GINT_TO_POINTER(offset));
             }
         } else {
@@ -523,8 +535,9 @@
         }
     }
 
-    if (haystack[offset+1] != '\0') {
-        *result = prof_occurrences(needle, haystack, offset+1, whole_word, result);
+    offset++;
+    if (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0) {
+        *result = prof_occurrences(needle, haystack, offset, whole_word, result);
     }
 
     return *result;
Index: profanity-0.5.0/tests/unittests/test_common.c
===================================================================
--- profanity-0.5.0.orig/tests/unittests/test_common.c	2016-09-15 23:53:43.000000000 +0200
+++ profanity-0.5.0/tests/unittests/test_common.c	2017-05-29 22:21:29.225862420 +0200
@@ -444,6 +444,13 @@
     assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5, hi",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     g_slist_free(expected); expected = NULL;
 
+    expected = g_slist_append(expected, GINT_TO_POINTER(0));
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而",      0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而 hi",   0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而: hi",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而, hi",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    g_slist_free(expected); expected = NULL;
+
     expected = g_slist_append(expected, GINT_TO_POINTER(6));
     assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5",        0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
@@ -451,6 +458,12 @@
     g_slist_free(expected); expected = NULL;
 
     expected = g_slist_append(expected, GINT_TO_POINTER(6));
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而",        0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 there",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "heyy @我能吞下玻璃而, there", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    g_slist_free(expected); expected = NULL;
+
+    expected = g_slist_append(expected, GINT_TO_POINTER(6));
     expected = g_slist_append(expected, GINT_TO_POINTER(26));
     assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 some more a boothj5 stuff",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there ands #boothj5",        0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
@@ -458,6 +471,13 @@
     g_slist_free(expected); expected = NULL;
 
     expected = g_slist_append(expected, GINT_TO_POINTER(6));
+    expected = g_slist_append(expected, GINT_TO_POINTER(26));
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 some more a 我能吞下玻璃而 stuff",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 there ands #我能吞下玻璃而",        0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "heyy @我能吞下玻璃而, there hows 我能吞下玻璃而?",       0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    g_slist_free(expected); expected = NULL;
+
+    expected = g_slist_append(expected, GINT_TO_POINTER(6));
     assert_true(_lists_equal(prof_occurrences("p", "ppppp p",   0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     g_slist_free(expected); expected = NULL;
 
@@ -488,4 +508,16 @@
     assert_true(_lists_equal(prof_occurrences("k",       "kk",                  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     assert_true(_lists_equal(prof_occurrences("k",       "kkkkkkk",                  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
     g_slist_free(expected); expected = NULL;
+
+    expected = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而hello",        0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而",          0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而hithere",   0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey 我能吞下玻璃而hithere",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey @我能吞下玻璃而hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而 hithere",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而, hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而我能吞下玻璃而",      0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而fill我能吞下玻璃而",  0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
+    g_slist_free(expected); expected = NULL;
 }
Index: profanity-0.5.0/tests/unittests/unittests.c
===================================================================
--- profanity-0.5.0.orig/tests/unittests/unittests.c	2016-09-15 23:53:43.000000000 +0200
+++ profanity-0.5.0/tests/unittests/unittests.c	2017-05-29 22:21:29.233862882 +0200
@@ -6,6 +6,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include <sys/stat.h>
+#include <locale.h>
 
 #include "config.h"
 #include "xmpp/chat_session.h"
@@ -37,6 +38,7 @@
 #include "test_plugins_disco.h"
 
 int main(int argc, char* argv[]) {
+    setlocale(LC_ALL, "");
     const UnitTest all_tests[] = {
 
         unit_test(replace_one_substr),

Reply via email to