commands: fix _checkUrl

This commit is contained in:
Valentin Lorentz 2021-08-25 23:28:25 +02:00
parent 0131cd0691
commit db05081ff6
2 changed files with 8 additions and 6 deletions

View File

@ -179,6 +179,8 @@ class WebTestCase(ChannelPluginTestCase):
def testFetchIri(self): def testFetchIri(self):
self.assertRegexp('fetch http://café.example.org/', self.assertRegexp('fetch http://café.example.org/',
'Error: .*is not a valid') 'Error: .*is not a valid')
self.assertRegexp('fetch http://example.org/café',
'Error: .*is not a valid')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -667,15 +667,15 @@ def getGlob(irc, msg, args, state):
glob = '*%s*' % glob glob = '*%s*' % glob
state.args.append(glob) state.args.append(glob)
def _checkUrl(url): def _checkUrl(state, url):
try: try:
args[0].encode('ascii') url.encode('ascii')
except UnicodeEncodeError: except UnicodeEncodeError:
state.errorInvalid(_('url'), args[0]) state.errorInvalid(_('url'), url)
def getUrl(irc, msg, args, state): def getUrl(irc, msg, args, state):
if utils.web.urlRe.match(args[0]): if utils.web.urlRe.match(args[0]):
_checkUrl(args[0]) _checkUrl(state, args[0])
state.args.append(args.pop(0)) state.args.append(args.pop(0))
else: else:
state.errorInvalid(_('url'), args[0]) state.errorInvalid(_('url'), args[0])
@ -694,10 +694,10 @@ def getEmail(irc, msg, args, state):
def getHttpUrl(irc, msg, args, state): def getHttpUrl(irc, msg, args, state):
if utils.web.httpUrlRe.match(args[0]): if utils.web.httpUrlRe.match(args[0]):
_checkUrl(args[0]) _checkUrl(state, args[0])
state.args.append(args.pop(0)) state.args.append(args.pop(0))
elif utils.web.httpUrlRe.match('http://' + args[0]): elif utils.web.httpUrlRe.match('http://' + args[0]):
_checkUrl('http://' + args[0]) _checkUrl(state, 'http://' + args[0])
state.args.append('http://' + args.pop(0)) state.args.append('http://' + args.pop(0))
else: else:
state.errorInvalid(_('http url'), args[0]) state.errorInvalid(_('http url'), args[0])