From 6fd69e84e6c395a108e6b2620c6428907b7d7efd Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Sat, 1 Sep 2018 16:17:33 -0500 Subject: [PATCH] common: Fix whitespace CTCP ignore invalid index When constructing a CTCP ignore, check that splitting on whitespace results in non-empty list before taking from the list. If it's empty, fall back to assuming any valid sender, i.e. "*"/".*" depending on whether the rule is set as wildcard or regex. This fixes issues when receiving a CTCP with an invalid CTCP ignore rule such as " ". --- src/common/ignorelistmanager.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/common/ignorelistmanager.h b/src/common/ignorelistmanager.h index 7bf4bab3..baf3cc10 100644 --- a/src/common/ignorelistmanager.h +++ b/src/common/ignorelistmanager.h @@ -122,10 +122,27 @@ public: // This is not performance-intensive; sticking with QRegExp for Qt 4 is fine // Split based on whitespace characters QStringList split(contents().split(QRegExp("\\s+"), QString::SkipEmptyParts)); - // Match on the first item - _cacheCtcpSender = split.takeFirst(); - // Track the rest as CTCP types to ignore - _cacheCtcpTypes = split; + // Match on the first item, handling empty rules/matches + if (!split.isEmpty()) { + // Take the first item as the sender + _cacheCtcpSender = split.takeFirst(); + // Track the rest as CTCP types to ignore + _cacheCtcpTypes = split; + } + else { + // No match found - this can happen if a pure whitespace CTCP ignore rule is + // created. Fall back to matching all senders. + if (_isRegEx) { + // RegEx match everything + _cacheCtcpSender = ".*"; + } + else { + // Wildcard match everything + _cacheCtcpSender = "*"; + } + // Clear the types (split is already empty) + _cacheCtcpTypes = split; + } } _type = type; } -- 2.20.1