Don't treat single words as URL

This commit is contained in:
Florian Bruhin 2014-05-06 14:25:11 +02:00
parent 8e122abd35
commit 7fb0a7745b
2 changed files with 5 additions and 1 deletions

View File

@ -137,6 +137,7 @@ class IsUrlNaiveTests(TestCase):
'foo bar',
'localhost test',
'another . test',
'foo',
]
def test_urls(self):

View File

@ -73,11 +73,14 @@ def _is_url_naive(url):
True if the url really is an URL, False otherwise.
"""
protocols = ['http', 'https']
u = qurl(url)
urlstr = urlstring(url)
if isinstance(url, QUrl):
u = url
else:
u = QUrl.fromUserInput(url)
if u.scheme() in protocols:
# We don't use u here because fromUserInput appends http:// automatically.
if any(urlstr.startswith(proto) for proto in protocols):
return True
elif '.' in u.host():
return True