Skip to content

Commit 50f2d4d

Browse files
committed
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
1 parent 95f62f3 commit 50f2d4d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

test/unit/autolinker_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,14 @@ describe("autolinker", function () {
209209
],
210210
]);
211211
});
212+
213+
it("should correctly find emails with hyphens in domain (bug 20557)", function () {
214+
testLinks([
215+
[
216+
"john.doe@faculity.uni-cityname.tld",
217+
"mailto:john.doe@faculity.uni-cityname.tld",
218+
],
219+
["john.doe@uni-cityname.tld", "mailto:john.doe@uni-cityname.tld"],
220+
]);
221+
});
212222
});

web/autolinker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Autolinker {
138138
static findLinks(text) {
139139
// Regex can be tested and verified at https://regex101.com/r/rXoLiT/2.
140140
this.#regex ??=
141-
/\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;
141+
/\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;
142142

143143
const [normalizedText, diffs] = normalize(text, { ignoreDashEOL: true });
144144
const matches = normalizedText.matchAll(this.#regex);

0 commit comments

Comments
 (0)