From 59710fc19e76d6b8022afb53c9a9d8248cc9902f Mon Sep 17 00:00:00 2001 From: Shaun McCance Date: Sat, 28 Aug 2021 20:33:52 -0400 Subject: 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 */ -- cgit v1.2.1