mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Filter RTL unicode characters out
Gajim sends \u200E and \u200F for RTL. It is planned that Gajim stops doing this and uses some GTK feature to get the same result. However users expressed the whish that we filter out such characters in incoming messages before displaying them to make Profanity more robust. I'm still not sure whether I like the solution because it means a lot of allocating/deallocating upon every new message. Fix https://github.com/profanity-im/profanity/issues/1220
This commit is contained in:
parent
750355acc4
commit
87f9bacffa
@ -68,6 +68,8 @@
|
||||
|
||||
#include "ui/ui.h"
|
||||
|
||||
static void _clean_incoming_message(ProfMessage *message);
|
||||
|
||||
void
|
||||
sv_ev_login_account_success(char *account_name, gboolean secured)
|
||||
{
|
||||
@ -326,6 +328,7 @@ sv_ev_room_message(ProfMessage *message)
|
||||
|
||||
GList *triggers = prefs_message_get_triggers(message->plain);
|
||||
|
||||
_clean_incoming_message(message);
|
||||
mucwin_incoming_msg(mucwin, message, mentions, triggers);
|
||||
|
||||
g_slist_free(mentions);
|
||||
@ -397,6 +400,8 @@ sv_ev_incoming_private_message(ProfMessage *message)
|
||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
||||
privatewin = (ProfPrivateWin*)window;
|
||||
}
|
||||
|
||||
_clean_incoming_message(message);
|
||||
privwin_incoming_msg(privatewin, message);
|
||||
chat_log_msg_in(message);
|
||||
|
||||
@ -418,6 +423,8 @@ sv_ev_delayed_private_message(ProfMessage *message)
|
||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
||||
privatewin = (ProfPrivateWin*)window;
|
||||
}
|
||||
|
||||
_clean_incoming_message(message);
|
||||
privwin_incoming_msg(privatewin, message);
|
||||
chat_log_msg_in(message);
|
||||
|
||||
@ -529,6 +536,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
|
||||
message->plain = p_gpg_decrypt(message->encrypted);
|
||||
if (message->plain) {
|
||||
message->enc = PROF_MSG_ENC_PGP;
|
||||
_clean_incoming_message(message);
|
||||
chatwin_incoming_msg(chatwin, message, new_win);
|
||||
if (logit) {
|
||||
chat_log_pgp_msg_in(message);
|
||||
@ -543,6 +551,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
|
||||
}
|
||||
message->enc = PROF_MSG_ENC_PLAIN;
|
||||
message->plain = strdup(message->body);
|
||||
_clean_incoming_message(message);
|
||||
chatwin_incoming_msg(chatwin, message, new_win);
|
||||
chat_log_msg_in(message);
|
||||
chatwin->pgp_recv = FALSE;
|
||||
@ -564,6 +573,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
|
||||
message->enc = PROF_MSG_ENC_PLAIN;
|
||||
}
|
||||
|
||||
_clean_incoming_message(message);
|
||||
chatwin_incoming_msg(chatwin, message, new_win);
|
||||
|
||||
chat_log_otr_msg_in(message);
|
||||
@ -578,6 +588,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
|
||||
static void
|
||||
_sv_ev_incoming_omemo(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
|
||||
{
|
||||
_clean_incoming_message(message);
|
||||
chatwin_incoming_msg(chatwin, message, new_win);
|
||||
if (logit) {
|
||||
chat_log_omemo_msg_in(message);
|
||||
@ -592,6 +603,7 @@ _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, ProfMessage *messa
|
||||
if (message->body) {
|
||||
message->enc = PROF_MSG_ENC_PLAIN;
|
||||
message->plain = strdup(message->body);
|
||||
_clean_incoming_message(message);
|
||||
chatwin_incoming_msg(chatwin, message, new_win);
|
||||
if (logit) {
|
||||
chat_log_msg_in(message);
|
||||
@ -1412,3 +1424,21 @@ sv_ev_bookmark_autojoin(Bookmark *bookmark)
|
||||
|
||||
free(nick);
|
||||
}
|
||||
|
||||
static void
|
||||
_clean_incoming_message(ProfMessage *message)
|
||||
{
|
||||
if (strstr(message->plain, "\u200E")) {
|
||||
char **split = g_strsplit(message->plain, "\u200E", -1);
|
||||
free(message->plain);
|
||||
message->plain = g_strjoinv("", split);
|
||||
g_strfreev(split);
|
||||
}
|
||||
|
||||
if (strstr(message->plain, "\u200F")) {
|
||||
char **split = g_strsplit(message->plain, "\u200F", -1);
|
||||
free(message->plain);
|
||||
message->plain = g_strjoinv("", split);
|
||||
g_strfreev(split);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user