From 38e6ac324337d83e4ea9a08ca95765907c579303 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 9 Sep 2026 15:10:35 +0000 Subject: [PATCH] Require an allowed TLD in fuzzy email hosts Fuzzy links anchor on the TLD list, but since d4a73a4 the fuzzy email host accepted any final label, so `user@example.badtld` was linkified. Anchor the email host on the TLD list too, the same way `get_fuzzy_url_host_port` does. - Add a `not_links` fixture for an email with an unknown TLD. Closes #123 --- src/rebuilder.ts | 6 ++++-- test/fixtures/not_links.txt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rebuilder.ts b/src/rebuilder.ts index 55fbd69..7e0db54 100644 --- a/src/rebuilder.ts +++ b/src/rebuilder.ts @@ -291,12 +291,14 @@ export class REBuilder { } get_fuzzy_mail_host () { - // Similar to normal mail host, but without local domains. + // Similar to normal mail host, but + // - TLD as anchor + // - No local domains return this.cache.src_fuzzy_mail_host ??= new RegExp( '(?:' + this.get_ipv6_mail_host().source + '|' + - `(?:(?:(?:${this.get_domain().source})[.]){1,4}${this.get_domain_root().source})` + + `(?:(?:(?:${this.get_domain().source})[.]){1,4}(?:${this.get_tld().source}))` + ')' + this.get_host_terminator().source ) diff --git a/test/fixtures/not_links.txt b/test/fixtures/not_links.txt index 2247f8b..2925b4c 100644 --- a/test/fixtures/not_links.txt +++ b/test/fixtures/not_links.txt @@ -53,6 +53,7 @@ http://[1:2:3:4:5:6:7:8:9]/ % Not email % foo@bar % Should be at second level domain & with correct tld +foo@bar.badtld mailto:bar mailto:user@[::1] mailto:user@[IPv6:202:NaN]