Skip to content

Commit

Permalink
Check against decoding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocj89 committed Aug 25, 2024
1 parent 172e0ce commit 1a63bf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion eas/api/instagram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class Comment:


def _extract_media_pk(url):
return _CLIENT.media_pk_from_url(url)
try:
return _CLIENT.media_pk_from_url(url)
except ValueError as e:
LOG.info("Invalid instagram URL %r: %s", url, e)
raise InvalidURL(f"Invalid URL: {url}") from e


def _fetch_comments(url):
Expand Down
6 changes: 6 additions & 0 deletions eas/api/tests/int/test_lamadava.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ def test_fail_on_disabled_comments(requestsm):
)
with pytest.raises(InvalidURL):
get_comments(url)


def test_fail_on_invalid_url_decode():
url = "https://www.instagram.com/tintin.personal.shopper/?next=%2Fajinomai%2F"
with pytest.raises(InvalidURL):
get_comments(url)

0 comments on commit 1a63bf7

Please sign in to comment.