aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-10-23 06:46:30 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-10-23 06:46:30 +0000
commit996e5fa630b6275c598d8c2c573b9803b1752f83 (patch)
treedabe591efc6bbf1a3b7bb53669bead9db082f7fd
parentconfig: add color.sixelN options (diff)
Revert "url-mode: don't strip the file:// prefix from localhost URIs"
This reverts commit 54722369d8ca0c6b90c6d874b0f712e133cd4925.
-rw-r--r--url-mode.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/url-mode.c b/url-mode.c
index c6340e94..20c9820b 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -129,17 +129,46 @@ static void
activate_url(struct seat *seat, struct terminal *term, const struct url *url,
uint32_t serial)
{
+ char *url_string = NULL;
+
+ char *scheme, *host, *path;
+ if (uri_parse(url->url, strlen(url->url), &scheme, NULL, NULL,
+ &host, NULL, &path, NULL, NULL))
+ {
+ if (strcmp(scheme, "file") == 0 && hostname_is_localhost(host)) {
+ /*
+ * This is a file in *this* computer. Pass only the
+ * filename to the URL-launcher.
+ *
+ * I.e. strip the ‘file://user@host/’ prefix.
+ */
+ url_string = path;
+ } else
+ free(path);
+
+ free(scheme);
+ free(host);
+ }
+
+ if (url_string == NULL)
+ url_string = xstrdup(url->url);
+
switch (url->action) {
case URL_ACTION_COPY:
- text_to_clipboard(seat, term, xstrdup(url->url), seat->kbd.serial);
+ if (text_to_clipboard(seat, term, url_string, seat->kbd.serial)) {
+ /* Now owned by our clipboard “manager” */
+ url_string = NULL;
+ }
break;
case URL_ACTION_LAUNCH:
case URL_ACTION_PERSISTENT: {
- spawn_url_launcher(seat, term, url->url, serial);
+ spawn_url_launcher(seat, term, url_string, serial);
break;
}
}
+
+ free(url_string);
}
void