mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Alias: correct unescaping of alias names when creating registry entries in Alias.__init__
Only a problem when the rules on allowed alias names were relaxed, in which case backslashes were duplicated every time the bot restarted. Also factor out '.' and '|' checks into needsEscaping function
This commit is contained in:
parent
711572b5b2
commit
fd53d8c410
@ -102,9 +102,12 @@ def findBiggestAt(alias):
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def needsEscaping(alias):
|
||||||
|
return '.' in alias or '|' in alias
|
||||||
|
|
||||||
def escapeAlias(alias):
|
def escapeAlias(alias):
|
||||||
"""Encodes [a-z0-9.]+ into [a-z][a-z0-9].
|
"""Encodes dots and pipes
|
||||||
Format: a<number of escaped chars>a(<index>d)+<word without dots>."""
|
Format: a<number of escaped chars>a(<index>(d|p))+<word without dots or pipes>."""
|
||||||
prefix = ''
|
prefix = ''
|
||||||
new_alias = ''
|
new_alias = ''
|
||||||
prefixes = 0
|
prefixes = 0
|
||||||
@ -242,19 +245,19 @@ class Alias(callbacks.Plugin):
|
|||||||
# XXX This should go. aliases should be a space separate list, etc.
|
# XXX This should go. aliases should be a space separate list, etc.
|
||||||
group = conf.supybot.plugins.Alias.aliases
|
group = conf.supybot.plugins.Alias.aliases
|
||||||
group2 = conf.supybot.plugins.Alias.escapedaliases
|
group2 = conf.supybot.plugins.Alias.escapedaliases
|
||||||
|
prefixLen = len(registry.split('supybot.plugins.alias.aliases'))
|
||||||
for (name, alias) in registry._cache.items():
|
for (name, alias) in registry._cache.items():
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
|
nameSplit = registry.split(name)
|
||||||
|
if len(nameSplit) > prefixLen+1:
|
||||||
|
continue
|
||||||
if name.startswith('supybot.plugins.alias.aliases.'):
|
if name.startswith('supybot.plugins.alias.aliases.'):
|
||||||
name = name[len('supybot.plugins.alias.aliases.'):]
|
name = nameSplit[-1]
|
||||||
if '.' in name:
|
|
||||||
continue
|
|
||||||
conf.registerGlobalValue(group, name, registry.String('', ''))
|
conf.registerGlobalValue(group, name, registry.String('', ''))
|
||||||
conf.registerGlobalValue(group.get(name), 'locked',
|
conf.registerGlobalValue(group.get(name), 'locked',
|
||||||
registry.Boolean(False, ''))
|
registry.Boolean(False, ''))
|
||||||
elif name.startswith('supybot.plugins.alias.escapedaliases.'):
|
elif name.startswith('supybot.plugins.alias.escapedaliases.'):
|
||||||
name = name[len('supybot.plugins.alias.escapedaliases.'):]
|
name = nameSplit[-1]
|
||||||
if '.' in name:
|
|
||||||
continue
|
|
||||||
conf.registerGlobalValue(group2, name,
|
conf.registerGlobalValue(group2, name,
|
||||||
registry.String('', ''))
|
registry.String('', ''))
|
||||||
conf.registerGlobalValue(group2.get(name),
|
conf.registerGlobalValue(group2.get(name),
|
||||||
@ -355,7 +358,7 @@ class Alias(callbacks.Plugin):
|
|||||||
raise AliasError(format('Alias %q is locked.', name))
|
raise AliasError(format('Alias %q is locked.', name))
|
||||||
f = makeNewAlias(name, alias)
|
f = makeNewAlias(name, alias)
|
||||||
f = types.MethodType(f, self)
|
f = types.MethodType(f, self)
|
||||||
if '.' in name or '|' in name:
|
if needsEscaping(name):
|
||||||
aliasGroup = self.registryValue('escapedaliases', value=False)
|
aliasGroup = self.registryValue('escapedaliases', value=False)
|
||||||
confname = escapeAlias(name)
|
confname = escapeAlias(name)
|
||||||
else:
|
else:
|
||||||
@ -375,7 +378,7 @@ class Alias(callbacks.Plugin):
|
|||||||
if name in self.aliases and self.isCommandMethod(name):
|
if name in self.aliases and self.isCommandMethod(name):
|
||||||
if evenIfLocked or not self.aliases[name][1]:
|
if evenIfLocked or not self.aliases[name][1]:
|
||||||
del self.aliases[name]
|
del self.aliases[name]
|
||||||
if '.' in name or '|' in name:
|
if needsEscaping(name):
|
||||||
conf.supybot.plugins.Alias.escapedaliases.unregister(
|
conf.supybot.plugins.Alias.escapedaliases.unregister(
|
||||||
escapeAlias(name))
|
escapeAlias(name))
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user