[totem-pl-parser] lines: Fix parsing of m3u files



commit 21f64b6252445a79660797296d15b4cfa4e21360
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 26 17:36:17 2015 +0100

    lines: Fix parsing of m3u files
    
    This was broken since commit d2caf76e0646f29ee8edcc89627398d8363dd327
    (and version 3.10.4) which changed the functions used to emit new
    playlist items.
    
    We didn't take enough care to replace totem_pl_parser_add_one_file()
    calls by TOTEM_PL_PARSER_FIELD_FILE fields, and passed GFiles as URIs
    instead, leading to garbage being added, and possibly to crashes.
    
    Include test case to avoid this sort of error in the future.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758710

 plparse/tests/Makefile.am       |    3 ++-
 plparse/tests/parser.c          |   21 +++++++++++++++++++--
 plparse/tests/relative.m3u      |    1 +
 plparse/totem-pl-parser-lines.c |    4 ++--
 4 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index 8aae89d..ae32c96 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -75,6 +75,7 @@ EXTRA_DIST =                  \
        no-url-podcast.xml      \
        xml-base.xspf           \
        radioclasica.mp3.m3u    \
-       radios-freebox.m3u
+       radios-freebox.m3u      \
+       relative.m3u
 
 -include $(top_srcdir)/git.mk
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 45fa7d4..a271f2b 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -283,8 +283,12 @@ entry_parsed_cb (TotemPlParser *parser,
                 GHashTable *metadata,
                 ParserResult *res)
 {
-       if (res->ret == NULL)
-               res->ret = g_strdup (g_hash_table_lookup (metadata, res->field));
+       if (res->ret == NULL) {
+               if (g_strcmp0 (res->field, TOTEM_PL_PARSER_FIELD_URI) == 0)
+                       res->ret = g_strdup (uri);
+               else
+                       res->ret = g_strdup (g_hash_table_lookup (metadata, res->field));
+       }
 }
 
 static void
@@ -545,6 +549,18 @@ test_m3u_audio_track (void)
 }
 
 static void
+test_m3u_relative (void)
+{
+       char *uri, *file_uri;
+
+       uri = get_relative_uri (TEST_SRCDIR "relative.m3u");
+       file_uri = get_relative_uri (TEST_SRCDIR "3gpp-file.mp4");
+       g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_URI), ==, file_uri);
+       g_free (uri);
+       g_free (file_uri);
+}
+
+static void
 test_pl_content_type (void)
 {
        char *uri;
@@ -1263,6 +1279,7 @@ main (int argc, char *argv[])
                g_test_add_func ("/parser/resolution", test_resolution);
                g_test_add_func ("/parser/parsability", test_parsability);
                g_test_add_func ("/parser/image_link", test_image_link);
+               g_test_add_func ("/parser/m3u_relative", test_m3u_relative);
                g_test_add_func ("/parser/m3u_audio_track", test_m3u_audio_track);
                g_test_add_func ("/parser/no_url_podcast", test_no_url_podcast);
                g_test_add_func ("/parser/xml_is_text_plain", test_xml_is_text_plain);
diff --git a/plparse/tests/relative.m3u b/plparse/tests/relative.m3u
new file mode 100644
index 0000000..b2819df
--- /dev/null
+++ b/plparse/tests/relative.m3u
@@ -0,0 +1 @@
+3gpp-file.mp4
diff --git a/plparse/totem-pl-parser-lines.c b/plparse/totem-pl-parser-lines.c
index 3136d55..98f9662 100644
--- a/plparse/totem-pl-parser-lines.c
+++ b/plparse/totem-pl-parser-lines.c
@@ -502,7 +502,7 @@ totem_pl_parser_add_m3u (TotemPlParser *parser,
                        /* + 2, skip drive letter */
                        uri = g_file_get_child (base_file, line + 2);
                        totem_pl_parser_add_uri (parser,
-                                                TOTEM_PL_PARSER_FIELD_URI, uri,
+                                                TOTEM_PL_PARSER_FIELD_FILE, uri,
                                                 TOTEM_PL_PARSER_FIELD_TITLE, 
totem_pl_parser_get_extinfo_title (extinfo),
                                                 TOTEM_PL_PARSER_FIELD_AUDIO_TRACK, audio_track,
                                                 NULL);
@@ -536,7 +536,7 @@ totem_pl_parser_add_m3u (TotemPlParser *parser,
                        uri = g_file_get_child (_base_file, line);
                        g_object_unref (_base_file);
                        totem_pl_parser_add_uri (parser,
-                                                TOTEM_PL_PARSER_FIELD_URI, uri,
+                                                TOTEM_PL_PARSER_FIELD_FILE, uri,
                                                 TOTEM_PL_PARSER_FIELD_TITLE, 
totem_pl_parser_get_extinfo_title (extinfo),
                                                 TOTEM_PL_PARSER_FIELD_AUDIO_TRACK, audio_track,
                                                 NULL);


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