[tracker] libtracker-sparql: Fix off by one in checks for escaped IRIs



commit cc13adfb270553866b8c7dcd8b80c8cfa863b800
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Sep 4 11:30:15 2022 +0200

    libtracker-sparql: Fix off by one in checks for escaped IRIs
    
    The 0x20 character should also be escaped as per the SPARQL reference,
    and it correctly is when setting a TrackerResource IRI. Even though,
    the fast path check for the presence of characters that should be
    escaped is missing it, so it would be possible to let IRIs that only
    have this invalid character as valid.
    
    Since 0x20 (whitespace) is possibly the most ubiquitous character that
    should be escaped, it's a bit of an oversight.
    
    Fixes: 33031007c ("libtracker-sparql: Escape illegal characters in IRIREF...")

 src/libtracker-sparql/tracker-resource.c        | 4 ++--
 tests/libtracker-sparql/tracker-resource-test.c | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index fc7ea265a..32975654e 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -104,8 +104,8 @@ escape_iri (const gchar *str)
        /* Fast path, check whether there's no characters to escape */
        if (!strpbrk (str,
                      "<>\"{}|^`"
-                     "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                     "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f")) {
+                     "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
+                     "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20")) {
                return g_strdup (str);
        }
 
diff --git a/tests/libtracker-sparql/tracker-resource-test.c b/tests/libtracker-sparql/tracker-resource-test.c
index aa78ea552..c08cd150a 100644
--- a/tests/libtracker-sparql/tracker-resource-test.c
+++ b/tests/libtracker-sparql/tracker-resource-test.c
@@ -231,6 +231,12 @@ test_resource_iri_valid_chars (void)
        g_assert_cmpstr (tracker_resource_get_first_uri (resource, "rdf:type"), ==, 
"http://example.com/resource";);
        g_object_unref (resource);
 
+       resource = tracker_resource_new ("http://example.com/A B");
+       tracker_resource_set_uri (resource, "rdf:type", "http://example.com/A B");
+       g_assert_cmpstr (tracker_resource_get_identifier (resource), ==, "http://example.com/A%20B";);
+       g_assert_cmpstr (tracker_resource_get_first_uri (resource, "rdf:type"), ==, 
"http://example.com/A%20B";);
+       g_object_unref (resource);
+
        resource = tracker_resource_new ("http://example.com/♥️";);
        tracker_resource_set_uri (resource, "rdf:type", "http://example.com/♥️";);
        g_assert_cmpstr (tracker_resource_get_identifier (resource), ==, "http://example.com/♥️";);


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