From 94703c5c4f5b0062bf7bf4b9d326203eac3b6999 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Fri, 27 Mar 2026 03:13:04 +0000 Subject: [PATCH] fix(share): use urls.PathEscape for mailto share links per RFC 6068 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enabled by new Hugo v0.153 release. Replace the brittle `urlquery` + blanket `+` → `%20` workaround with Hugo's `urls.PathEscape` for mailto URIs, which natively percent-encodes spaces as `%20`. The old approach could corrupt titles containing literal `+` characters. --- .../layouts/_partials/components/page_sharer.html | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/blox/layouts/_partials/components/page_sharer.html b/modules/blox/layouts/_partials/components/page_sharer.html index 10bcac40..5b90f29e 100644 --- a/modules/blox/layouts/_partials/components/page_sharer.html +++ b/modules/blox/layouts/_partials/components/page_sharer.html @@ -2,14 +2,11 @@
{{ range where site.Data.page_sharer.links "enable" true }} - {{/* Utilise `urlquery` over `htmlEscape` to encode sharing URL */}} - {{/* See https://github.com/HugoBlox/kit/pull/2726 */}} - {{ $link := replace .url "{url}" ($.Permalink | urlquery) }} - {{ $link = replace $link "{title}" ($.Title | urlquery) }} - {{/* Workaround `urlquery` encoding for mailto as `urlquery` encodes `+` as `%2B` and ` ` (space) as `+` */}} - {{ if eq (urls.Parse $link).Scheme "mailto" }} - {{ $link = replace $link "+" "%20" }} - {{ end }} + {{/* mailto URIs require percent-encoding (%20 for spaces) per RFC 6068, not form-encoding (+ for spaces). */}} + {{/* Use urls.PathEscape for mailto; urlquery for other schemes (https, etc.). */}} + {{ $is_mailto := eq (urls.Parse .url).Scheme "mailto" }} + {{ $link := replace .url "{url}" (cond $is_mailto (urls.PathEscape $.Permalink) (urlquery $.Permalink)) }} + {{ $link = replace $link "{title}" (cond $is_mailto (urls.PathEscape $.Title) (urlquery $.Title)) }}