From 3bccc63125b671b81cb5575349e01f5fbedb68e0 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 18 Mar 2023 13:58:59 +0100 Subject: [PATCH] Fix +S stripping too much on incorrect color codes. Reported by semioriginal in https://bugs.unrealircd.org/view.php?id=5908 with the patch also by semioriginal. --- src/misc.c | 3 ++- src/modules/message.c | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/misc.c b/src/misc.c index 52d27a7e8..5e571db7e 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2595,7 +2595,8 @@ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen while (len > 0) { - if ( col && ((isdigit(*text) && nc < 2) || (*text == ',' && nc < 3))) + if ((col && isdigit(*text) && nc < 2) || + ((col == 1) && (*text == ',') && isdigit(text[1]) && (nc > 0) && (nc < 3))) { nc++; if (*text == ',') diff --git a/src/modules/message.c b/src/modules/message.c index 43290faba..bcea1e7ea 100644 --- a/src/modules/message.c +++ b/src/modules/message.c @@ -537,11 +537,15 @@ const char *_StripColors(const char *text) while (len > 0) { - if ((col && isdigit(*text) && nc < 2) || (col && *text == ',' && nc < 3)) + if ((col && isdigit(*text) && nc < 2) || + ((col == 1) && (*text == ',') && isdigit(text[1]) && (nc > 0) && (nc < 3))) { nc++; if (*text == ',') + { nc = 0; + col++; + } } /* Syntax for RGB is ^DHHHHHH where H is a hex digit. * If < 6 hex digits are specified, the code is displayed