utils.url: Always treat URLs with explicit scheme as URL.

This commit is contained in:
Florian Bruhin 2014-08-08 13:04:52 +02:00
parent 8ab022407b
commit 45657141a0

View File

@ -78,14 +78,11 @@ def _is_url_naive(urlstr):
Return: Return:
True if the URL really is a URL, False otherwise. True if the URL really is a URL, False otherwise.
""" """
schemes = ('http', 'https')
url = QUrl.fromUserInput(urlstr) url = QUrl.fromUserInput(urlstr)
# We don't use url here because fromUserInput appends http:// # We don't use url here because fromUserInput appends http://
# automatically. # automatically.
if not url.isValid(): if not url.isValid():
return False return False
elif QUrl(urlstr).scheme() in schemes:
return True
elif '.' in url.host(): elif '.' in url.host():
return True return True
elif url.host() == 'localhost': elif url.host() == 'localhost':
@ -171,16 +168,21 @@ def is_url(urlstr):
logger.debug("Checking if '{}' is a URL (autosearch={}).".format( logger.debug("Checking if '{}' is a URL (autosearch={}).".format(
urlstr, autosearch)) urlstr, autosearch))
qurl = QUrl(urlstr)
if not autosearch: if not autosearch:
# no autosearch, so everything is a URL. # no autosearch, so everything is a URL.
return True return True
if ' ' in urlstr: if qurl.isValid() and qurl.scheme():
# URLs with explicit schemes are always URLs
logger.debug("Contains explicit scheme")
return True
elif ' ' in urlstr:
# A URL will never contain a space # A URL will never contain a space
logger.debug("Contains space -> no URL") logger.debug("Contains space -> no URL")
return False return False
elif is_special_url(QUrl(urlstr)): elif is_special_url(qurl):
# Special URLs are always URLs, even with autosearch=False # Special URLs are always URLs, even with autosearch=False
logger.debug("Is an special URL.") logger.debug("Is an special URL.")
return True return True