[gupnp-av] Fix node filtering in DIDLLiteWriter



commit 1b77e99156d3b0f3372cf021cd5a4f556f4a8343
Author: Jens Georg <mail jensge org>
Date:   Wed Nov 7 14:13:34 2012 +0100

    Fix node filtering in DIDLLiteWriter
    
    Completely match node names, avoid matching prefixes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687462

 libgupnp-av/gupnp-didl-lite-writer.c |   12 ++++++++++--
 tests/gtest/test-regression.c        |   23 +++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-writer.c b/libgupnp-av/gupnp-didl-lite-writer.c
index 8ad2097..ca11a70 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.c
+++ b/libgupnp-av/gupnp-didl-lite-writer.c
@@ -107,7 +107,7 @@ static int
 compare_node_name (const char *a, const char *b)
 {
         const char *p;
-        int len;
+        int len, result;
 
         if (a[0] == '@')
                 /* Filter is for top-level property */
@@ -120,7 +120,15 @@ compare_node_name (const char *a, const char *b)
         else
                 len = strlen (a);
 
-        return strncmp (a, b, len);
+        result = strncmp (a, b, len);
+
+        if (result == 0) {
+            /* Avoid that we return a match although only prefixes match like
+             * in upnp:album and upnp:albumArtUri, cf. bgo#687462 */
+            return strlen (b) - len;
+        }
+
+        return result;
 }
 
 static gboolean
diff --git a/tests/gtest/test-regression.c b/tests/gtest/test-regression.c
index d535636..e5bbedd 100644
--- a/tests/gtest/test-regression.c
+++ b/tests/gtest/test-regression.c
@@ -20,6 +20,7 @@
  */
 
 #include <libgupnp-av/gupnp-didl-lite-parser.h>
+#include <libgupnp-av/gupnp-didl-lite-writer.h>
 
 #define TEST_DIDL_BGO674319 \
 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
@@ -68,12 +69,34 @@ test_bgo674319 (void)
         g_assert (artists == NULL);
 }
 
+static void
+test_bgo687462 (void)
+{
+        GUPnPDIDLLiteWriter *writer;
+        GUPnPDIDLLiteObject *object;
+
+        writer = gupnp_didl_lite_writer_new (NULL);
+        object = (GUPnPDIDLLiteObject *)
+                                gupnp_didl_lite_writer_add_item (writer);
+        gupnp_didl_lite_object_set_album (object, "Test");
+        g_assert_cmpstr (gupnp_didl_lite_object_get_album (object), ==, "Test");
+
+        gupnp_didl_lite_object_set_album_art (object, "AlbumArt");
+        g_assert_cmpstr (gupnp_didl_lite_object_get_album_art (object), ==, "AlbumArt");
+
+        gupnp_didl_lite_writer_filter (writer, "upnp:album");
+
+        g_assert_cmpstr (gupnp_didl_lite_object_get_album (object), ==, "Test");
+        g_assert (gupnp_didl_lite_object_get_album_art (object) == NULL);
+}
+
 int main (int argc, char *argv[])
 {
         g_type_init ();
         g_test_init (&argc, &argv, NULL);
 
         g_test_add_func ("/bugs/gnome/674319", test_bgo674319);
+        g_test_add_func ("/bugs/gnome/687462", test_bgo687462);
 
         g_test_run ();
 



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