fix enriching single-letter second level domain

This commit is contained in:
chroju 2023-03-12 09:07:28 +09:00
parent 86df301550
commit 615448ae23
No known key found for this signature in database
GPG Key ID: 7F63A4E620B812C8
2 changed files with 4 additions and 1 deletions

View File

@ -11,7 +11,7 @@ function tag(name: string, content: string, attrs: Record<string, string> = {}):
return `<${name}${htmlAttrs}>${content}</${name}>`
}
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

View File

@ -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)