pidgin: 5dc6f235: Make purple_utf8_has_word() better about...
datallah at pidgin.im
datallah at pidgin.im
Thu Dec 18 23:15:46 EST 2008
-----------------------------------------------------------------
Revision: 5dc6f2359f155e18525e7b42ecd827005e473725
Ancestor: 2ea831c9d9fa347deb4c363b061869f050d29419
Author: datallah at pidgin.im
Date: 2008-12-19T04:11:15
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5dc6f2359f155e18525e7b42ecd827005e473725
Modified files:
libpurple/util.c
ChangeLog:
Make purple_utf8_has_word() better about detecting word boundaries (still not
really "correct") and prevent stuff like "&" spuriously matching a nick of
"amp". Fixes #7328.
-------------- next part --------------
============================================================
--- libpurple/util.c 6ae64429a3c33a57e4fba7b1447bcf633c7f07a4
+++ libpurple/util.c b1e2422dba120c0c8639cfbace7fc771d728b9d4
@@ -4572,18 +4572,35 @@ purple_utf8_has_word(const char *haystac
purple_utf8_has_word(const char *haystack, const char *needle)
{
char *hay, *pin, *p;
+ const char *start, *prev_char;
+ gunichar before, after;
int n;
gboolean ret = FALSE;
- hay = g_utf8_strdown(haystack, -1);
+ start = hay = g_utf8_strdown(haystack, -1);
pin = g_utf8_strdown(needle, -1);
n = strlen(pin);
- if ((p = strstr(hay, pin)) != NULL) {
- if ((p == hay || !isalnum(*(p - 1))) && !isalnum(*(p + n))) {
+ while ((p = strstr(start, pin)) != NULL) {
+ prev_char = g_utf8_find_prev_char(hay, p);
+ before = -2;
+ if (prev_char) {
+ before = g_utf8_get_char(prev_char);
+ }
+ after = g_utf8_get_char_validated(p + n, - 1);
+
+ if ((p == hay ||
+ /* The character before is a reasonable guess for a word boundary
+ ("!g_unichar_isalnum()" is not a valid way to determine word
+ boundaries, but it is the only reasonable thing to do here),
+ and isn't the '&' from a "&" or some such entity*/
+ (before != -2 && !g_unichar_isalnum(before) && *(p - 1) != '&'))
+ && after != -2 && !g_unichar_isalnum(after)) {
ret = TRUE;
+ break;
}
+ start = p + 1;
}
g_free(pin);
More information about the Commits
mailing list