mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-22 10:04:25 +01:00
Alias: Prevent @add from allowing invalid names.
This commit is contained in:
parent
73f63c25b9
commit
a2f115e09f
@ -317,10 +317,12 @@ class Alias(callbacks.Plugin):
|
|||||||
irc.error(_('There is no such alias.'))
|
irc.error(_('There is no such alias.'))
|
||||||
unlock = wrap(unlock, [('checkCapability', 'admin'), 'commandName'])
|
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):
|
def addAlias(self, irc, name, alias, lock=False):
|
||||||
if self._invalidCharsRe.search(name):
|
if not self._validNameRe.search(name):
|
||||||
raise AliasError, 'Names cannot contain spaces or square brackets.'
|
raise AliasError('Names can only contain alphanumerical '
|
||||||
|
'characters and dots and pipes (and the first letter '
|
||||||
|
'cannot be a number).')
|
||||||
realName = callbacks.canonicalName(name)
|
realName = callbacks.canonicalName(name)
|
||||||
if name != realName:
|
if name != realName:
|
||||||
s = format(_('That name isn\'t valid. Try %q instead.'), realName)
|
s = format(_('That name isn\'t valid. Try %q instead.'), realName)
|
||||||
|
@ -112,6 +112,9 @@ class AliasTestCase(ChannelPluginTestCase):
|
|||||||
self.failIf('foobar' in cb.aliases)
|
self.failIf('foobar' in cb.aliases)
|
||||||
self.assertError('foobar')
|
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):
|
def testOptionalArgs(self):
|
||||||
self.assertNotError('alias add myrepr "repr @1"')
|
self.assertNotError('alias add myrepr "repr @1"')
|
||||||
self.assertResponse('myrepr foo', '"foo"')
|
self.assertResponse('myrepr foo', '"foo"')
|
||||||
|
Loading…
Reference in New Issue
Block a user