Skip to content

Self-hosted AI workspace.

Python

fix: is_youtube_url (services) crashes on a non-string url (#1753)

Afonso Coutinho71f35f259500
diff --git a/services/youtube/youtube_handler.py b/services/youtube/youtube_handler.py
index c775becf6..b8f1384dd 100644
--- a/services/youtube/youtube_handler.py
+++ b/services/youtube/youtube_handler.py
@@ -59,6 +59,8 @@ def init_youtube():
def is_youtube_url(url: str) -> bool:
+ if not isinstance(url, str):
+ return False
return "youtube.com" in url or "youtu.be" in url
diff --git a/tests/test_is_youtube_url_nonstring_svc.py b/tests/test_is_youtube_url_nonstring_svc.py
new file mode 100644
index 000000000..20af55848
--- /dev/null
+++ b/tests/test_is_youtube_url_nonstring_svc.py
@@ -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