[libgdata] [youtube] Check the hostname when extracting video IDs from URIs



commit 11feedf628437743836ec02bb2ed22bd35672d66
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Jul 8 15:26:18 2009 +0100

    [youtube] Check the hostname when extracting video IDs from URIs

 gdata/services/youtube/gdata-youtube-video.c |    5 ++++-
 gdata/tests/youtube.c                        |    7 +++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index 3ea48f8..651b5bf 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -1314,6 +1314,9 @@ gdata_youtube_video_set_recorded (GDataYouTubeVideo *self, GTimeVal *recorded)
  * gdata_youtube_video_get_video_id(), and the @video_uri should be in the same form as returned by
  * gdata_youtube_video_get_player_uri().
  *
+ * The function will validate whether the URI actually points to a hostname containing <literal>youtube</literal>
+ * (e.g. <literal>youtube.com</literal>), and will return %NULL if it doesn't.
+ *
  * For example:
  * <informalexample><programlisting>
  * video_id = gdata_youtube_video_get_video_id_from_uri ("http://www.youtube.com/watch?v=BH_vwsyCrTc&feature=featured";);
@@ -1336,7 +1339,7 @@ gdata_youtube_video_get_video_id_from_uri (const gchar *video_uri)
 	uri = soup_uri_new (video_uri);
 	if (uri == NULL)
 		return NULL;
-	else if (uri->query == NULL) {
+	else if (uri->query == NULL || uri->host == NULL || strstr (uri->host, "youtube") == NULL) {
 		soup_uri_free (uri);
 		return NULL;
 	}
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index af3f411..c68b891 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -634,6 +634,13 @@ test_parsing_video_id_from_uri (void)
 	g_assert_cmpstr (video_id, ==, "BH_vwsyCrTc");
 	g_free (video_id);
 
+	video_id = gdata_youtube_video_get_video_id_from_uri ("http://www.youtube.es/watch?v=foo";);
+	g_assert_cmpstr (video_id, ==, "foo");
+	g_free (video_id);
+
+	video_id = gdata_youtube_video_get_video_id_from_uri ("http://foobar.com/watch?v=foo";);
+	g_assert (video_id == NULL);
+
 	video_id = gdata_youtube_video_get_video_id_from_uri ("http://foobar.com/not/real";);
 	g_assert (video_id == NULL);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]