summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2021-08-28 20:33:52 -0400
committerShaun McCance <shaunm@gnome.org>2021-08-28 20:37:52 -0400
commit59710fc19e76d6b8022afb53c9a9d8248cc9902f (patch)
treed10327d4c7445a7e174f909398590a5ad4bf1a76
parentfced64d5ba8ca2825b16a3f904d6dba5011d9eb1 (diff)
downloadyelp-59710fc19e76d6b8022afb53c9a9d8248cc9902f.tar.gz
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
-rw-r--r--libyelp/yelp-uri-builder.c23
1 files 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 */