Refactor slashguard
Fixes #2054 Fixes:95c2199c("Some more memory improvements") Signed-off-by: Steffen Jaeckel <s@jaeckel.eu> (cherry picked from commit40aafd06e7)
This commit is contained in:
@@ -170,6 +170,25 @@ create_input_window(void)
|
||||
_inp_win_update_virtual();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_inp_slashguard_check(void)
|
||||
{
|
||||
if (get_password)
|
||||
return false;
|
||||
/* ignore empty and quoted messages */
|
||||
if (inp_line == NULL || inp_line[0] == '\0' || inp_line[0] == '>')
|
||||
return false;
|
||||
if (!prefs_get_boolean(PREF_SLASH_GUARD))
|
||||
return false;
|
||||
if (memchr(inp_line + 1, '/', 3)) {
|
||||
cons_show("Your text contains a slash in the first 4 characters");
|
||||
free(inp_line);
|
||||
inp_line = NULL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char*
|
||||
inp_readline(void)
|
||||
{
|
||||
@@ -203,17 +222,7 @@ inp_readline(void)
|
||||
chat_state_idle();
|
||||
}
|
||||
|
||||
if (inp_line) {
|
||||
if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) {
|
||||
// ignore quoted messages
|
||||
if (strlen(inp_line) > 1 && inp_line[0] != '>') {
|
||||
char* res = (char*)memchr(inp_line + 1, '/', 3);
|
||||
if (res) {
|
||||
cons_show("Your text contains a slash in the first 4 characters");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inp_line && !_inp_slashguard_check()) {
|
||||
char* ret = inp_line;
|
||||
inp_line = NULL;
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user