Alias: Prevent @add from allowing invalid names.

This commit is contained in:
Valentin Lorentz 2013-08-15 13:30:12 +02:00
parent 73f63c25b9
commit a2f115e09f
2 changed files with 8 additions and 3 deletions

View File

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

View File

@ -112,6 +112,9 @@ 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')
def testOptionalArgs(self):
self.assertNotError('alias add myrepr "repr @1"')
self.assertResponse('myrepr foo', '"foo"')