From da58669de5c061e7ecac8d3a1fdf9da00db603e7 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 23 Aug 2019 21:01:55 -0700 Subject: [PATCH] parse_modes: case fold parameters to modes --- classes.py | 14 ++++++++++++-- test/protocol_test_fixture.py | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/classes.py b/classes.py index 5e9722c..7dea015 100644 --- a/classes.py +++ b/classes.py @@ -906,6 +906,13 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): args = args[1:] existing = set(existing) + existing_casemap = {} + for modepair in existing: + arg = modepair[1] + if arg is not None: + existing_casemap[(modepair[0], self.to_lower(arg))] = modepair + else: + existing_casemap[modepair] = modepair res = [] for mode in modestring: @@ -947,10 +954,13 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): log.debug('(%s) parse_modes: checking if +%s %s is in old modes list: %s', self.name, mode, arg, existing) - if (mode, arg) not in existing: - # Ignore attempts to unset bans that don't exist. + arg = self.to_lower(arg) + casefolded_modepair = existing_casemap.get((mode, arg)) # Case fold arguments as needed + if casefolded_modepair not in existing: + # Ignore attempts to unset parameter modes that don't exist. log.debug("(%s) parse_modes(): ignoring removal of non-existent list mode +%s %s", self.name, mode, arg) continue + arg = casefolded_modepair[1] elif prefix == '+' and mode in supported_modes['*C']: # Only has parameter when setting. diff --git a/test/protocol_test_fixture.py b/test/protocol_test_fixture.py index 1019a6c..4ebd100 100644 --- a/test/protocol_test_fixture.py +++ b/test/protocol_test_fixture.py @@ -382,6 +382,13 @@ class BaseProtocolTest(unittest.TestCase): [('-b', '*!*@test1')], "First ban should have been removed (different case)" ) + self.p.apply_modes('#testruns', [('+b', '*!*@Test2')]) + self.assertEqual( + # remove second ban despite different case + self.p.parse_modes('#testruns', ['-b', '*!*@test2']), + [('-b', '*!*@Test2')], + "Second ban should have been removed (different case)" + ) def test_parse_modes_user_rfc(self): u = self._make_user('testuser', uid='100')