mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
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
This commit is contained in:
parent
95f62f3b33
commit
50f2d4db65
@ -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"],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user