Strip trailing colons from link detection, add test ()

This commit is contained in:
Eric Bailey 2023-12-08 11:44:43 -06:00 committed by GitHub
parent 842e183925
commit 60deea1762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions
.changeset
packages/api

@ -0,0 +1,5 @@
---
'@atproto/api': patch
---
Strip trailing colon from URLs in rich-text facet detection.

@ -47,7 +47,7 @@ export function detectFacets(text: UnicodeString): Facet[] | undefined {
const start = text.utf16.indexOf(match[2], match.index)
const index = { start, end: start + match[2].length }
// strip ending puncuation
if (/[.,;!?]$/.test(uri)) {
if (/[.,;:!?]$/.test(uri)) {
uri = uri.slice(0, -1)
index.end--
}

@ -41,6 +41,7 @@ describe('detectFacets', () => {
'start middle end.com/foo/bar?baz=bux#hash',
'newline1.com\nnewline2.com',
'a example.com/index.php php link',
'a trailing bsky.app: colon',
'not.. a..url ..here',
'e.g.',
@ -162,6 +163,7 @@ describe('detectFacets', () => {
['example.com/index.php', 'https://example.com/index.php'],
[' php link'],
],
[['a trailing '], ['bsky.app', 'https://bsky.app'], [': colon']],
[['not.. a..url ..here']],
[['e.g.']],