From 6ea2d062b79424ea039974b0f36949d0a9095e89 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 31 Oct 2012 16:35:51 +0000 Subject: [PATCH] Web: Filter special chars in @title, and add --no-filter. I'm adding --no-filter just in case someone want to use @title to do this at purpose --- plugins/Web/plugin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 2b943e85d..e6be52593 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -174,10 +174,12 @@ class Web(callbacks.PluginRegexp): size = wrap(size, ['httpUrl']) @internationalizeDocstring - def title(self, irc, msg, args, url): - """ + def title(self, irc, msg, args, optlist, url): + """[--no-filter] Returns the HTML ... of a URL. + If --no-filter is given, the bot won't strip special chars (action, + DCC, ...). """ size = conf.supybot.protocols.http.peekSize() text = utils.web.getUrl(url, size=size) \ @@ -189,13 +191,17 @@ class Web(callbacks.PluginRegexp): self.log.debug('Encountered a problem parsing %u. Title may ' 'already be set, though', url) if parser.title: - irc.reply(utils.web.htmlToText(parser.title.strip())) + title = utils.web.htmlToText(parser.title.strip()) + if not [y for x,y in optlist if x == 'no-filter']: + for i in range(1, 4): + title = title.replace(chr(i), '') + irc.reply(title) elif len(text) < size: irc.reply(_('That URL appears to have no HTML title.')) else: irc.reply(format(_('That URL appears to have no HTML title ' 'within the first %S.'), size)) - title = wrap(title, ['httpUrl']) + title = wrap(title, [getopts({'no-filter': ''}), 'httpUrl']) _netcraftre = re.compile(r'td align="left">\s+]+>(.*?)