mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Fixed bug #941101.
This commit is contained in:
parent
8274d5dfb9
commit
2c2e21e765
@ -231,6 +231,11 @@ class RSS(callbacks.Privmsg):
|
||||
def getHeadlines(self, feed):
|
||||
return [utils.htmlToText(d['title'].strip()) for d in feed['items']]
|
||||
|
||||
def _validFeedName(self, name):
|
||||
if not registry.isValidRegistryName(name):
|
||||
raise ValueError, name
|
||||
return callbacks.canonicalName(name)
|
||||
|
||||
def makeFeedCommand(self, name, url):
|
||||
docstring = """<number of headlines>
|
||||
|
||||
@ -240,7 +245,7 @@ class RSS(callbacks.Privmsg):
|
||||
seconds, which defaults to 1800 (30 minutes) since that's what most
|
||||
websites prefer.
|
||||
""" % (name, url)
|
||||
name = callbacks.canonicalName(name)
|
||||
assert name == self._validFeedName(name)
|
||||
if url not in self.locks:
|
||||
self.locks[url] = threading.RLock()
|
||||
if hasattr(self, name):
|
||||
@ -262,6 +267,12 @@ class RSS(callbacks.Privmsg):
|
||||
given URL.
|
||||
"""
|
||||
(name, url) = privmsgs.getArgs(args, required=2)
|
||||
try:
|
||||
name = self._validFeedName(name)
|
||||
except ValueError:
|
||||
irc.error('%r is not a valid feed name. Feed names must not '
|
||||
'include dots, colons, or spaces.' % name)
|
||||
return
|
||||
self.makeFeedCommand(name, url)
|
||||
irc.replySuccess()
|
||||
|
||||
@ -317,7 +328,7 @@ class RSS(callbacks.Privmsg):
|
||||
try:
|
||||
n = int(n)
|
||||
except ValueError:
|
||||
raise callbacks.Error
|
||||
raise callbacks.ArgumentError
|
||||
headlines = headlines[:n]
|
||||
headlines = imap(utils.htmlToText, headlines)
|
||||
sep = self.registryValue('headlineSeparator', channel)
|
||||
|
@ -47,6 +47,9 @@ class RegistryException(Exception):
|
||||
class InvalidRegistryFile(RegistryException):
|
||||
pass
|
||||
|
||||
class InvalidRegistryName(RegistryException):
|
||||
pass
|
||||
|
||||
class InvalidRegistryValue(RegistryException):
|
||||
pass
|
||||
|
||||
@ -100,6 +103,9 @@ def close(registry, filename, annotated=True, helpOnceOnly=False):
|
||||
fd.write('%s: %s\n' % (name, value))
|
||||
fd.close()
|
||||
|
||||
def isValidRegistryName(name):
|
||||
return '.' not in name and ':' not in name and len(name.split()) == 1
|
||||
|
||||
|
||||
class Group(object):
|
||||
def __init__(self, supplyDefault=False):
|
||||
@ -161,6 +167,8 @@ class Group(object):
|
||||
pass
|
||||
|
||||
def register(self, name, node=None):
|
||||
if not isValidRegistryName(name):
|
||||
raise InvalidRegistryName, name
|
||||
if node is None:
|
||||
node = Group()
|
||||
if name not in self.children: # XXX Is this right?
|
||||
|
@ -63,6 +63,11 @@ if network:
|
||||
finally:
|
||||
conf.supybot.reply.whenNotCommand.setValue(orig)
|
||||
|
||||
def testRssAddBadName(self):
|
||||
self.assertError('rss add . %s' % url)
|
||||
self.assertError('rss add : %s' % url)
|
||||
self.assertError('rss add "foo bar" %s' % url)
|
||||
|
||||
def testCantAddFeedNamedRss(self):
|
||||
self.assertError('rss add rss %s' % url)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user