From 50f2d4db65f4eb272a6d18e37bf3d3e21c63ea7d Mon Sep 17 00:00:00 2001 From: Alessio Attilio Date: Sun, 25 Jan 2026 17:20:14 +0100 Subject: [PATCH] fix: allow hyphens in mailto link auto-detection (bug 20557) Modified the regex in web/autolinker.js to explicitly allow hyphens (-) in the domain part of email addresses, while maintaining the exclusion of other punctuation. This fixes mailto links like user@uni-city.tld being truncated at the hyphen. Fixes #20557 --- test/unit/autolinker_spec.js | 10 ++++++++++ web/autolinker.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/unit/autolinker_spec.js b/test/unit/autolinker_spec.js index 2063e07f8..f92d148df 100644 --- a/test/unit/autolinker_spec.js +++ b/test/unit/autolinker_spec.js @@ -209,4 +209,14 @@ describe("autolinker", function () { ], ]); }); + + it("should correctly find emails with hyphens in domain (bug 20557)", function () { + testLinks([ + [ + "john.doe@faculity.uni-cityname.tld", + "mailto:john.doe@faculity.uni-cityname.tld", + ], + ["john.doe@uni-cityname.tld", "mailto:john.doe@uni-cityname.tld"], + ]); + }); }); diff --git a/web/autolinker.js b/web/autolinker.js index a3045235e..f0e659387 100644 --- a/web/autolinker.js +++ b/web/autolinker.js @@ -138,7 +138,7 @@ class Autolinker { static findLinks(text) { // Regex can be tested and verified at https://regex101.com/r/rXoLiT/2. this.#regex ??= - /\b(?:https?:\/\/|mailto:|www\.)(?:[\S--[\p{P}<>]]|\/|[\S--[\[\]]]+[\S--[\p{P}<>]])+|(?=\p{L})[\S--[@\p{Ps}\p{Pe}<>]]+@([\S--[\p{P}<>]]+(?:\.[\S--[\p{P}<>]]+)+)/gmv; + /\b(?:https?:\/\/|mailto:|www\.)(?:[\S--[\p{P}<>]]|\/|[\S--[\[\]]]+[\S--[\p{P}<>]])+|(?=\p{L})[\S--[@\p{Ps}\p{Pe}<>]]+@([\S--[[\p{P}--\-]<>]]+(?:\.[\S--[[\p{P}--\-]<>]]+)+)/gmv; const [normalizedText, diffs] = normalize(text, { ignoreDashEOL: true }); const matches = normalizedText.matchAll(this.#regex);