3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 12:12:53 +01:00

parse_modes: case fold parameters to modes

This commit is contained in:
James Lu 2019-08-23 21:01:55 -07:00
parent 6ad34672d3
commit da58669de5
2 changed files with 19 additions and 2 deletions

View File

@ -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.

View File

@ -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')