Skip to content

Commit 8648d5a

Browse files
committed
Removed trailing slashes from URLs
1 parent a0cfb48 commit 8648d5a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

telegram/utils/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def extract_urls(message):
143143
if message.caption:
144144
all_urls += _extract_urls_from_text(message.caption)
145145

146+
# Strip trailing slash from URL so we can compare them for equality
147+
stripped_urls = [x[:-1] if x[-1] == '/' else x for x in all_urls]
148+
146149
# Remove exact duplicates
147-
urls = OrderedDict({k: None for k in all_urls})
150+
urls = OrderedDict({k: None for k in stripped_urls})
148151
return list(urls.keys())

tests/test_helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def test_extract_urls_entities(self):
5656
entities=[MessageEntity(**e) for e in test_entities])
5757
result = helpers.extract_urls(test_message)
5858

59-
assert len(result) == 3
60-
assert (test_entities[0]['url'] == result[0])
61-
assert (result[1] == 'http://github.com')
62-
assert (test_entities[2]['url'] == result[2])
59+
assert len(result) == 2
60+
assert (test_entities[0]['url'][:-1] == result[0])
61+
assert (result[0] == 'http://github.com')
62+
assert (test_entities[2]['url'] == result[1])
6363

6464
def test_extract_urls_caption(self):
6565
caption = "Taken from https://stackoverflow.com/questions/520031/whats" \

0 commit comments

Comments
 (0)