Mercurial > irccd
changeset 447:108e63b449eb release-2.1
Fix #645: rules are case sensitive
Convert to lowercase rule properties since IRC is case-insensitive in most of
the cases.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 20 Jul 2017 16:06:55 +0200 |
parents | edeb5210fe81 |
children | 8b615d37d303 |
files | CHANGES.md libirccd/irccd/rule.cpp tests/rules/main.cpp |
diffstat | 3 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.md Sun Jul 02 08:10:17 2017 +0200 +++ b/CHANGES.md Thu Jul 20 16:06:55 2017 +0200 @@ -1,6 +1,12 @@ IRC Client Daemon CHANGES ========================= +irccd 2.1.3 +---------------------- + + - Rules are now case insensitive (#645). + + irccd 2.1.2 2017-06-02 ----------------------
--- a/libirccd/irccd/rule.cpp Sun Jul 02 08:10:17 2017 +0200 +++ b/libirccd/irccd/rule.cpp Thu Jul 20 16:06:55 2017 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <algorithm> +#include <cctype> #include <stdexcept> #include "logger.hpp" @@ -74,10 +76,15 @@ const std::string &plugin, const std::string &event) const noexcept { - return matchMap(m_servers, server) && - matchMap(m_channels, channel) && - matchMap(m_origins, nick) && - matchMap(m_plugins, plugin) && + auto tolower = [] (auto str) { + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + return str; + }; + + return matchMap(m_servers, tolower(server)) && + matchMap(m_channels, tolower(channel)) && + matchMap(m_origins, tolower(nick)) && + matchMap(m_plugins, tolower(plugin)) && matchMap(m_events, event); }
--- a/tests/rules/main.cpp Sun Jul 02 08:10:17 2017 +0200 +++ b/tests/rules/main.cpp Thu Jul 20 16:06:55 2017 +0200 @@ -18,6 +18,7 @@ #include <gtest/gtest.h> +#include <irccd/logger.hpp> #include <irccd/rule.hpp> #include <irccd/service.hpp> @@ -228,10 +229,16 @@ ASSERT_FALSE(m_rules.solve("malikania", "#test", "", "game", "onMessage")); } +TEST_F(RulesTest, case_fix_645) +{ + ASSERT_FALSE(m_rules.solve("MALIKANIA", "#STAFF", "", "SYSTEM", "onCommand")); +} + } // !irccd int main(int argc, char **argv) { + irccd::log::setLogger(std::make_unique<irccd::log::SilentLogger>()); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();