Skip to content

Commit be88530

Browse files
committed
commands: Disallow IRIs from 'url' and 'httpUrl' converters.
urllib doesn't support IRIs, and gives out a cryptic 'UnicodeEncodeError: 'ascii' codec can't encode character ...' if we don't validate it.
1 parent 62db3a9 commit be88530

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

plugins/Web/test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,9 @@ def testNonSnarfingRegexpConfigurable(self):
176176
finally:
177177
conf.supybot.plugins.Web.nonSnarfingRegexp.set('')
178178

179+
def testFetchIri(self):
180+
self.assertRegexp('fetch http://café.example.org/',
181+
'Error: .*is not a valid')
182+
179183

180184
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

src/commands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,15 @@ def getGlob(irc, msg, args, state):
667667
glob = '*%s*' % glob
668668
state.args.append(glob)
669669

670+
def _checkUrl(url):
671+
try:
672+
args[0].encode('ascii')
673+
except UnicodeEncodeError:
674+
state.errorInvalid(_('url'), args[0])
675+
670676
def getUrl(irc, msg, args, state):
671677
if utils.web.urlRe.match(args[0]):
678+
_checkUrl(args[0])
672679
state.args.append(args.pop(0))
673680
else:
674681
state.errorInvalid(_('url'), args[0])
@@ -681,8 +688,10 @@ def getEmail(irc, msg, args, state):
681688

682689
def getHttpUrl(irc, msg, args, state):
683690
if utils.web.httpUrlRe.match(args[0]):
691+
_checkUrl(args[0])
684692
state.args.append(args.pop(0))
685693
elif utils.web.httpUrlRe.match('http://' + args[0]):
694+
_checkUrl('http://' + args[0])
686695
state.args.append('http://' + args.pop(0))
687696
else:
688697
state.errorInvalid(_('http url'), args[0])

0 commit comments

Comments
 (0)