Merge pull request #281 from cjmayo/python3_30

{python3_30} Python3: fix decoding strings
This commit is contained in:
anarcat 2019-09-11 09:47:10 -04:00 committed by GitHub
commit 492058a360
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -158,7 +158,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)
@ -247,7 +247,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