fix: is_youtube_url (services) crashes on a non-string url (#1753)
This commit is contained in:
@@ -59,6 +59,8 @@ def init_youtube():
|
|||||||
|
|
||||||
|
|
||||||
def is_youtube_url(url: str) -> bool:
|
def is_youtube_url(url: str) -> bool:
|
||||||
|
if not isinstance(url, str):
|
||||||
|
return False
|
||||||
return "youtube.com" in url or "youtu.be" in url
|
return "youtube.com" in url or "youtu.be" in url
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
tests/test_is_youtube_url_nonstring_svc.py
Normal file
13
tests/test_is_youtube_url_nonstring_svc.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from services.youtube.youtube_handler import is_youtube_url
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_youtube_url_handles_non_string():
|
||||||
|
# `"youtube.com" in url` raises TypeError on a non-string url.
|
||||||
|
assert is_youtube_url(123) is False
|
||||||
|
assert is_youtube_url(None) is False
|
||||||
|
assert is_youtube_url(["https://youtu.be/x"]) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_youtube_url_detects_real_urls():
|
||||||
|
assert is_youtube_url("https://www.youtube.com/watch?v=x") is True
|
||||||
|
assert is_youtube_url("https://youtu.be/x") is True
|
||||||
Reference in New Issue
Block a user