From 996e5fa630b6275c598d8c2c573b9803b1752f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 23 Oct 2024 08:46:30 +0200 Subject: [PATCH] Revert "url-mode: don't strip the file:// prefix from localhost URIs" This reverts commit 54722369d8ca0c6b90c6d874b0f712e133cd4925. --- url-mode.c | 33 +++++++++++++++++++++++++++++++-- 1 file 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