Make sure QUrl::fromUserInput is valid in is_url.
Fixes #460. Without this fix, it's possible for URLs to be valid according to is_url, but not according to QUrl::fromUserInput, e.g. "http:foo:0". This caused an exception later because fuzzy_url runs qtutils.ensure_valid.
This commit is contained in:
parent
3eac528716
commit
354018efcd
@ -157,6 +157,7 @@ class IsUrlTests(unittest.TestCase):
|
|||||||
'1337',
|
'1337',
|
||||||
'deadbeef',
|
'deadbeef',
|
||||||
'31c3',
|
'31c3',
|
||||||
|
'http:foo:0',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_urls(self, configmock):
|
def test_urls(self, configmock):
|
||||||
|
@ -205,25 +205,26 @@ def is_url(urlstr):
|
|||||||
if _has_explicit_scheme(qurl):
|
if _has_explicit_scheme(qurl):
|
||||||
# URLs with explicit schemes are always URLs
|
# URLs with explicit schemes are always URLs
|
||||||
log.url.debug("Contains explicit scheme")
|
log.url.debug("Contains explicit scheme")
|
||||||
return True
|
url = True
|
||||||
elif ' ' in urlstr:
|
elif ' ' in urlstr:
|
||||||
# A URL will never contain a space
|
# A URL will never contain a space
|
||||||
log.url.debug("Contains space -> no URL")
|
log.url.debug("Contains space -> no URL")
|
||||||
return False
|
url = False
|
||||||
elif is_special_url(qurl):
|
elif is_special_url(qurl):
|
||||||
# Special URLs are always URLs, even with autosearch=False
|
# Special URLs are always URLs, even with autosearch=False
|
||||||
log.url.debug("Is an special URL.")
|
log.url.debug("Is an special URL.")
|
||||||
return True
|
url = True
|
||||||
elif autosearch == 'dns':
|
elif autosearch == 'dns':
|
||||||
log.url.debug("Checking via DNS")
|
log.url.debug("Checking via DNS")
|
||||||
# We want to use qurl_from_user_input here, as the user might enter
|
# We want to use qurl_from_user_input here, as the user might enter
|
||||||
# "foo.de" and that should be treated as URL here.
|
# "foo.de" and that should be treated as URL here.
|
||||||
return _is_url_dns(qurl_from_user_input(urlstr))
|
url = _is_url_dns(qurl_from_user_input(urlstr))
|
||||||
elif autosearch == 'naive':
|
elif autosearch == 'naive':
|
||||||
log.url.debug("Checking via naive check")
|
log.url.debug("Checking via naive check")
|
||||||
return _is_url_naive(urlstr)
|
url = _is_url_naive(urlstr)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid autosearch value")
|
raise ValueError("Invalid autosearch value")
|
||||||
|
return url and QUrl.fromUserInput(urlstr).isValid()
|
||||||
|
|
||||||
|
|
||||||
def qurl_from_user_input(urlstr):
|
def qurl_from_user_input(urlstr):
|
||||||
|
Loading…
Reference in New Issue
Block a user