Python3: fix decoding strings

This commit is contained in:
Petr Dlouhý 2018-01-05 21:16:37 +01:00 committed by Chris Mayo
parent 5179e47c52
commit f272206110
2 changed files with 5 additions and 4 deletions

View file

@ -159,7 +159,7 @@ class MailtoUrl (urlbase.UrlBase):
{"addr": mail}, valid=False, overwrite=False)
return
# note: be sure to use rsplit since "@" can occur in local part
local, domain = mail.rsplit("@", 1)
local, domain = urlutil.decode_for_unquote(mail).rsplit("@", 1)
if not local:
self.set_result(_("Missing local part of mail address `%(addr)s'.") % \
{"addr": mail}, valid=False, overwrite=False)
@ -248,7 +248,7 @@ class MailtoUrl (urlbase.UrlBase):
from dns.exception import DNSException
log.debug(LOG_CHECK, "checking mail address %r", mail)
mail = strformat.ascii_safe(mail)
username, domain = mail.rsplit('@', 1)
username, domain = urlutil.decode_for_unquote(mail).rsplit('@', 1)
log.debug(LOG_CHECK, "looking up MX mailhost %r", domain)
try:
answers = resolver.query(domain, 'MX')

View file

@ -256,8 +256,9 @@ def url_fix_common_typos (url):
def url_fix_mailto_urlsplit (urlparts):
"""Split query part of mailto url if found."""
if "?" in urlparts[2]:
urlparts[2], urlparts[3] = urlparts[2].split('?', 1)
sep = b"?" if isinstance(urlparts[2], bytes) else u"?"
if sep in urlparts[2]:
urlparts[2], urlparts[3] = urlparts[2].split(sep, 1)
# wayback urls include in the path http[s]://. By default the
# tidying mechanism in linkchecker encodes the : and deletes the second slash