From 615448ae23581a0de35768e900c06084e1b0521c Mon Sep 17 00:00:00 2001 From: chroju Date: Sun, 12 Mar 2023 09:07:28 +0900 Subject: [PATCH] fix enriching single-letter second level domain --- backend/src/mastodon/microformats.ts | 2 +- backend/test/mastodon.spec.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/mastodon/microformats.ts b/backend/src/mastodon/microformats.ts index 72a4ee9..50a641e 100644 --- a/backend/src/mastodon/microformats.ts +++ b/backend/src/mastodon/microformats.ts @@ -11,7 +11,7 @@ function tag(name: string, content: string, attrs: Record = {}): return `<${name}${htmlAttrs}>${content}` } -const linkRegex = /(^|\s|\b)(https?:\/\/[-\w@:%._+~#=]{2,256}\.[a-z]{2,6}\b(?:[-\w@:%_+.~#?&/=]*))(\b|\s|$)/g +const linkRegex = /(^|\s|\b)(https?:\/\/[-\w@:%._+~#=]{1,256}\.[a-z]{2,6}\b(?:[-\w@:%_+.~#?&/=]*))(\b|\s|$)/g const mentionedEmailRegex = /(^|\s|\b|\W)@(\w+(?:[.-]?\w+)+@\w+(?:[.-]?\w+)+(?:\.\w{2,63})+)(\b|\s|$)/g const tagRegex = /(^|\s|\b|\W)#(\w{2,63})(\b|\s|$)/g diff --git a/backend/test/mastodon.spec.ts b/backend/test/mastodon.spec.ts index c5ca0ea..07c46d9 100644 --- a/backend/test/mastodon.spec.ts +++ b/backend/test/mastodon.spec.ts @@ -187,6 +187,9 @@ describe('Mastodon APIs', () => { 'http://www.cloudflare.co.uk?test=test@123', 'http://www.cloudflare.com/.com/?test=test@~123&a=b', 'https://developers.cloudflare.com/workers/runtime-apis/request/#background', + 'https://a.test', + 'https://a.test/test', + 'https://a.test/test?test=test', ] linksToTest.forEach((link) => { const url = new URL(link)