change protocol-relative urls to http
This commit is contained in:
parent
dfb623ce90
commit
d6074c1386
2 changed files with 7 additions and 7 deletions
|
|
@ -250,13 +250,13 @@ class TestTextToHTMLparser(TestCase):
|
||||||
def test_url_scheme_ftp(self):
|
def test_url_scheme_ftp(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.parser.convert_urls("ftp.example.com"),
|
self.parser.convert_urls("ftp.example.com"),
|
||||||
'<a href="//ftp.example.com" target="_blank">ftp.example.com</a>',
|
'<a href="http://ftp.example.com" target="_blank">ftp.example.com</a>',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_url_scheme_www(self):
|
def test_url_scheme_www(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.parser.convert_urls("www.example.com"),
|
self.parser.convert_urls("www.example.com"),
|
||||||
'<a href="//www.example.com" target="_blank">www.example.com</a>',
|
'<a href="http://www.example.com" target="_blank">www.example.com</a>',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_url_scheme_ftpproto(self):
|
def test_url_scheme_ftpproto(self):
|
||||||
|
|
@ -280,7 +280,7 @@ class TestTextToHTMLparser(TestCase):
|
||||||
def test_url_chars_slash(self):
|
def test_url_chars_slash(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.parser.convert_urls("www.example.com/homedir"),
|
self.parser.convert_urls("www.example.com/homedir"),
|
||||||
'<a href="//www.example.com/homedir" target="_blank">www.example.com/homedir</a>',
|
'<a href="http://www.example.com/homedir" target="_blank">www.example.com/homedir</a>',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_url_chars_colon(self):
|
def test_url_chars_colon(self):
|
||||||
|
|
@ -316,13 +316,13 @@ class TestTextToHTMLparser(TestCase):
|
||||||
def test_url_edge_following_period_eol(self):
|
def test_url_edge_following_period_eol(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.parser.convert_urls("www.example.com."),
|
self.parser.convert_urls("www.example.com."),
|
||||||
'<a href="//www.example.com" target="_blank">www.example.com</a>.',
|
'<a href="http://www.example.com" target="_blank">www.example.com</a>.',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_url_edge_following_period(self):
|
def test_url_edge_following_period(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.parser.convert_urls("see www.example.com. "),
|
self.parser.convert_urls("see www.example.com. "),
|
||||||
'see <a href="//www.example.com" target="_blank">www.example.com</a>. ',
|
'see <a href="http://www.example.com" target="_blank">www.example.com</a>. ',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_url_edge_brackets(self):
|
def test_url_edge_brackets(self):
|
||||||
|
|
|
||||||
|
|
@ -154,11 +154,11 @@ class TextToHTMLparser(object):
|
||||||
href = m.group(1)
|
href = m.group(1)
|
||||||
label = href
|
label = href
|
||||||
# if there is no protocol (i.e. starts with www or ftp)
|
# if there is no protocol (i.e. starts with www or ftp)
|
||||||
# prefix with // so the link isn't treated as relative
|
# prefix with http:// so the link isn't treated as relative
|
||||||
if not self.re_protocol.match(href):
|
if not self.re_protocol.match(href):
|
||||||
if not self.re_valid_no_protocol.match(href):
|
if not self.re_valid_no_protocol.match(href):
|
||||||
return text
|
return text
|
||||||
href = "//" + href
|
href = "http://" + href
|
||||||
rest = m.group(2)
|
rest = m.group(2)
|
||||||
# -> added target to output prevent the web browser from attempting to
|
# -> added target to output prevent the web browser from attempting to
|
||||||
# change pages (and losing our webclient session).
|
# change pages (and losing our webclient session).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue