Skip to content

Commit

Permalink
Strip trailing colons from link detection, add test (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey authored Dec 8, 2023
1 parent 842e183 commit 60deea1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/grumpy-vans-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/api': patch
---

Strip trailing colon from URLs in rich-text facet detection.
2 changes: 1 addition & 1 deletion packages/api/src/rich-text/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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--
}
Expand Down
2 changes: 2 additions & 0 deletions packages/api/tests/rich-text-detection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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.']],
Expand Down

0 comments on commit 60deea1

Please sign in to comment.