[yelp] Be more careful about stripping slashes



commit 59710fc19e76d6b8022afb53c9a9d8248cc9902f
Author: Shaun McCance <shaunm gnome org>
Date:   Sat Aug 28 20:33:52 2021 -0400

    Be more careful about stripping slashes
    
    The transition to GUri introduced some problems with our URI mangling,
    because it's more strict about URI syntax than libsoup was. This led
    to absolute file paths being broken. This ought to do it. Some day I
    might redo all of this, because it's a sloppy pile of legacy that's
    been monkeypatched thru half a dozen API changes in other libraries.
    That day is not today.
    
    Fixes #182
    cf https://bugzilla.redhat.com/show_bug.cgi?id=1997839

 libyelp/yelp-uri-builder.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/libyelp/yelp-uri-builder.c b/libyelp/yelp-uri-builder.c
index 9a8bdcf7..72084596 100644
--- a/libyelp/yelp-uri-builder.c
+++ b/libyelp/yelp-uri-builder.c
@@ -57,11 +57,16 @@ build_network_uri (const gchar *uri)
     if (g_str_equal (scheme, "ghelp") || g_str_equal (scheme, "gnome-help") ||
         g_str_equal (scheme, "help") || g_str_equal (scheme, "help-list") ||
         g_str_equal (scheme, "info") || g_str_equal (scheme, "man")) {
+        const gchar *upath = g_uri_get_path (guri);
         if (g_str_equal (scheme, "info") && fragment) {
-            path = g_strdup_printf ("/%s/%s", g_uri_get_path (guri), fragment);
+            if (upath[0] == '/')
+                path = g_strdup_printf ("%s/%s", upath, fragment);
+            else
+                path = g_strdup_printf ("/%s/%s", upath, fragment);
             fragment = NULL;
-        } else {
-            path = g_strdup_printf ("/%s", g_uri_get_path (guri));
+        }
+        else if (upath[0] != '/') {
+            path = g_strdup_printf ("/%s", upath);
         }
     }
 
@@ -95,10 +100,18 @@ build_yelp_uri (const gchar *uri_str)
 
   memmove (uri, uri + BOGUS_PREFIX_LEN, strlen (uri) - BOGUS_PREFIX_LEN + 1);
 
-  /* Remove the leading slash */
+  /* Remove some leading slashes */
   if ((resource = strstr (uri, ":"))) {
     resource++;
-    memmove (resource, resource + 1, strlen (resource));
+
+    if (g_str_has_prefix (uri, "help:")) {
+        if (resource[0] == '/')
+            memmove (resource, resource + 1, strlen (resource));
+    }
+    else if (g_str_has_prefix (uri, "ghelp:")) {
+        if (resource[0] == '/' && resource[1] == '/')
+            memmove (resource, resource + 1, strlen (resource));
+    }
   }
 
   /* Remove the trailing slash if any */


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