mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Refactor InspIRCd::StripColor.
- Only strip characters we actually recognise. - Strip the value for hex color codes.
This commit is contained in:
parent
5d801283bb
commit
babb39cb17
@ -2588,8 +2588,8 @@
|
||||
#<module name="starttls">
|
||||
|
||||
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
||||
# Strip color module: Adds channel mode +S that strips color codes and
|
||||
# all control codes except CTCP from all messages sent to the channel.
|
||||
# Strip color module: Adds channel mode +S that strips IRC formatting
|
||||
# characters from all messages sent to the channel.
|
||||
#<module name="stripcolor">
|
||||
|
||||
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
||||
|
@ -91,31 +91,51 @@ bool InspIRCd::IsValidMask(const std::string& mask)
|
||||
return true;
|
||||
}
|
||||
|
||||
void InspIRCd::StripColor(std::string& sentence)
|
||||
void InspIRCd::StripColor(std::string& line)
|
||||
{
|
||||
/* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
|
||||
int seq = 0;
|
||||
for (size_t idx = 0; idx < line.length(); )
|
||||
{
|
||||
switch (line[idx])
|
||||
{
|
||||
case '\x02': // Bold
|
||||
case '\x1D': // Italic
|
||||
case '\x11': // Monospace
|
||||
case '\x16': // Reverse
|
||||
case '\x1E': // Strikethrough
|
||||
case '\x1F': // Underline
|
||||
case '\x0F': // Reset
|
||||
line.erase(idx, 1);
|
||||
break;
|
||||
|
||||
for (std::string::iterator i = sentence.begin(); i != sentence.end();)
|
||||
case '\x03': // Color
|
||||
{
|
||||
if (*i == 3)
|
||||
seq = 1;
|
||||
else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
|
||||
auto start = idx;
|
||||
while (++idx < line.length() && idx - start < 6)
|
||||
{
|
||||
seq++;
|
||||
if ( (seq <= 4) && (*i == ',') )
|
||||
seq = 1;
|
||||
else if (seq > 3)
|
||||
seq = 0;
|
||||
const auto chr = line[idx];
|
||||
if (chr != ',' && (chr < '0' || chr > '9'))
|
||||
break;
|
||||
}
|
||||
line.erase(start, idx - start);
|
||||
break;
|
||||
}
|
||||
case '\x04': // Hex Color
|
||||
{
|
||||
auto start = idx;
|
||||
while (++idx < line.length() && idx - start < 14)
|
||||
{
|
||||
const auto chr = line[idx];
|
||||
if (chr != ',' && (chr < '0' || chr > '9') && (chr < 'A' || chr > 'F') && (chr < 'a' || chr > 'f'))
|
||||
break;
|
||||
}
|
||||
line.erase(start, idx - start);
|
||||
break;
|
||||
}
|
||||
else
|
||||
seq = 0;
|
||||
|
||||
// Strip all control codes too except \001 for CTCP
|
||||
if (seq || ((*i >= 0) && (*i < 32) && (*i != 1)))
|
||||
i = sentence.erase(i);
|
||||
else
|
||||
++i;
|
||||
default: // Non-formatting character.
|
||||
idx++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user