diff options
author | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-20 10:16:23 +0000 |
---|---|---|
committer | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-20 10:16:23 +0000 |
commit | 1bb1cb8f9f4fa3da13292d8209f941160e993899 (patch) | |
tree | 01e3c4fda76b3adacb14f6be8b67bfdd2fb34437 /src | |
parent | db9b9b0c84b4258660b81721a8ddcc0eb9f2ae4b (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_stripcolor.cpp | 63 |
1 files changed, 22 insertions, 41 deletions
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); } } } |