kopia lustrzana https://github.com/cloudflare/wildebeest
handle sub-domains correctly in enrichStatus
rodzic
9550a70269
commit
7c3353e90e
|
@ -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 {
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Ładowanie…
Reference in New Issue