File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -105,8 +105,11 @@ def mention_markdown(user_id, name):
105105 return '[{}](tg://user?id={})' .format (escape_markdown (name ), user_id )
106106
107107
108- def __extract_urls (text ):
109- """Returns a list of urls from a text string."""
108+ def _extract_urls_from_text (text ):
109+ """
110+ Returns a list of urls from a text string.
111+ URLs without a leading `http://` or `www.` won't be found.
112+ """
110113 out = []
111114 for word in text .split (' ' ):
112115 thing = urlparse (word .strip ())
@@ -138,7 +141,7 @@ def extract_urls(message):
138141 else k .url for k , v in results .items ()]
139142
140143 if message .caption :
141- all_urls += __extract_urls (message .caption )
144+ all_urls += _extract_urls_from_text (message .caption )
142145
143146 # Remove exact duplicates
144147 urls = OrderedDict ({k : None for k in all_urls })
Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ def test_escape_markdown(self):
2929
3030 assert expected_str == helpers .escape_markdown (test_str )
3131
32+ def test_extract_urls_from_text (self ):
33+ urls = "http://google.com and http://github.com/ and python-telegram-bot.readthedocs.io/en/latest/"
34+ result = helpers ._extract_urls_from_text (urls )
35+ assert len (result ) == 2
36+ assert result [0 ] == 'http://google.com'
37+ assert result [1 ] == 'http://github.com/'
38+
3239 def test_extract_urls_entities (self ):
3340 test_entities = [{
3441 'length' : 6 , 'offset' : 0 , 'type' : 'text_link' ,
You can’t perform that action at this time.
0 commit comments