Merge pull request #208 from cloudflare/fix-regexes-sub-domain

handle sub-domains correctly in enrichStatus
pull/209/head
Sven Sauleau 2023-02-06 23:55:03 +00:00 zatwierdzone przez GitHub
commit 0578e3ce8d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 16 dodań i 1 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ function tag(name: string, content: string, attrs: Record<string, string> = {}):
}
const linkRegex = /(^|\s|\b)(https?:\/\/[^.\s]+\.[^.\s]+(?:\/[^.\s/]+)*)(\b|\s|$)/g
const mentionedEmailRegex = /(^|\s|\b)@([^@\s\W]+@[^.\W\s]+\.[^.\s]+)(\b|\s|$)/g
const mentionedEmailRegex = /(^|\s|\b)@(\w+(?:[.-]?\w+)+@\w+(?:[.-]?\w+)+(?:\.\w{2,3})+)(\b|\s|$)/g
/// Transform a text status into a HTML status; enriching it with links / mentions.
export function enrichStatus(status: string): string {

Wyświetl plik

@ -309,6 +309,21 @@ describe('Mastodon APIs', () => {
enrichStatus('hello @test@example.com'),
'<p>hello <span class="h-card"><a href="https://example.com/@test" class="u-url mention">@<span>test</span></a></span></p>'
)
assert.equal(
enrichStatus('hello @test@example.eng.com'),
'<p>hello <span class="h-card"><a href="https://example.eng.com/@test" class="u-url mention">@<span>test</span></a></span></p>'
)
assert.equal(
enrichStatus('hello @test@example.eng.com!!!'),
'<p>hello <span class="h-card"><a href="https://example.eng.com/@test" class="u-url mention">@<span>test</span></a></span>!!!</p>'
)
assert.equal(
enrichStatus('hi @test.a.b.c-d@example.eng.co.uk.....'),
'<p>hi <span class="h-card"><a href="https://example.eng.co.uk/@test.a.b.c-d" class="u-url mention">@<span>test.a.b.c-d</span></a></span>.....</p>'
)
})
test('handle invalid mention', () => {