Alias: make regex for valid alias names configurable

This commit is contained in:
jacksonmj 2015-08-21 22:58:21 +00:00
parent 54e9b4be09
commit 963a17c817
3 changed files with 5 additions and 8 deletions

View File

@ -43,5 +43,7 @@ def configure(advanced):
Alias = conf.registerPlugin('Alias')
conf.registerGroup(Alias, 'aliases')
conf.registerGroup(Alias, 'escapedaliases')
conf.registerGlobalValue(Alias, 'validName',
registry.String(r'^[a-z.|!?][a-z0-9.|!]*$', _("""Regex which alias names must match in order to be valid""")))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -336,13 +336,9 @@ class Alias(callbacks.Plugin):
irc.error(_('There is no such alias.'))
unlock = wrap(unlock, [('checkCapability', 'admin'), 'commandName'])
_validNameRe = re.compile(r'^[a-z.|!?][a-z0-9.|!]*$')
def addAlias(self, irc, name, alias, lock=False):
if not self._validNameRe.search(name):
raise AliasError('Names can only contain alphanumerical '
'characters, dots, pipes, and '
'exclamation/interrogatin marks '
'(and the first character cannot be a number).')
if not re.search(self.registryValue('validName'), name):
raise AliasError('Invalid alias name.')
realName = callbacks.canonicalName(name)
if name != realName:
s = format(_('That name isn\'t valid. Try %q instead.'), realName)

View File

@ -112,8 +112,7 @@ class AliasTestCase(ChannelPluginTestCase):
self.failIf('foobar' in cb.aliases)
self.assertError('foobar')
self.assertRegexp('alias add café ignore', 'Error.*can only contain')
self.assertRegexp('alias add 1abc ignore', 'Error.*can only contain')
self.assertRegexp('alias add abc\x07 ignore', 'Error.*Invalid')
def testOptionalArgs(self):
self.assertNotError('alias add myrepr "repr @1"')