From 1bb1cb8f9f4fa3da13292d8209f941160e993899 Mon Sep 17 00:00:00 2001 From: peavey Date: Wed, 20 Jun 2007 10:16:23 +0000 Subject: Fix problem where in certain cases a \0 would be sent out. Thx to network Hak5IRC for reporting this. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7391 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_stripcolor.cpp | 63 ++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp index 25d2f5a49..3b51746ce 100644 --- a/src/modules/m_stripcolor.cpp +++ b/src/modules/m_stripcolor.cpp @@ -112,52 +112,33 @@ class ModuleStripColor : public Module DELETE(csc); } - // ANSI colour stripping based on C example by Doc (Peter Wood) virtual void ReplaceLine(std::string &sentence) { - int i, a, len, remove; - len = sentence.length(); - - for (i = 0; i < len; i++) - { - remove = 0; - - switch (sentence[i]) + /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */ + int seq = 0; + std::string::iterator i,safei; + for (i = sentence.begin(); i != sentence.end(); ++i) + { + if (((*i == 31) || (*i == 3))) { - case 2: - case 15: - case 22: - case 21: - case 31: - remove++; - break; - - case 3: - remove = 1; - - if (isdigit(sentence[i + remove])) - remove++; - - if (isdigit(sentence[i + remove])) - remove++; - - if (sentence[i + remove] == ',') - { - remove += 2; - - if (isdigit(sentence[i + remove])) - remove++; - } - break; + seq = 1; } - - if (remove != 0) + else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) ) { - len -= remove; - - for (a = i; a <= len; a++) - sentence[a] = sentence[a + remove]; - i--; + seq++; + if ( (seq <= 4) && (*i == ',') ) + seq = 1; + else if (seq > 3) + seq = 0; + } + else + seq = 0; + + if (seq) + { + safei = i; + --i; + sentence.erase(safei); } } } -- cgit v1.2.3