From dbe38f541c6e59607b99b9d26a6f74aafe9e08fc Mon Sep 17 00:00:00 2001 From: Kev Date: Thu, 27 Apr 2023 15:38:00 +0000 Subject: [PATCH] Parse URLs after sentence dot correctly --- packages/api/src/rich-text/util.ts | 2 +- packages/api/tests/rich-text-detection.test.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/api/src/rich-text/util.ts b/packages/api/src/rich-text/util.ts index cafd93d84e0..d79bde0a96e 100644 --- a/packages/api/src/rich-text/util.ts +++ b/packages/api/src/rich-text/util.ts @@ -1,6 +1,6 @@ export const MENTION_REGEX = /(^|\s|\()(@)([a-zA-Z0-9.-]+)(\b)/g export const URL_REGEX = - /(^|\s|\()((https?:\/\/[\S]+)|((?[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/gim + /(^|\s|\(|\b)((https?:\/\/[\S]+)|((?[a-z][a-z0-9]*(?!\.https?:\/\/)(\.[a-z0-9]+)+)[\S]*))/gim export const TRAILING_PUNCTUATION_REGEX = /\p{P}+$/gu /** diff --git a/packages/api/tests/rich-text-detection.test.ts b/packages/api/tests/rich-text-detection.test.ts index c87b5eab0a6..025a895b63c 100644 --- a/packages/api/tests/rich-text-detection.test.ts +++ b/packages/api/tests/rich-text-detection.test.ts @@ -32,6 +32,8 @@ describe('detectFacets', () => { 'start middle https://end.com/foo/bar?baz=bux#hash', 'https://newline1.com\nhttps://newline2.com', '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง https://middle.com ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง', + 'Check this out.https://afterdot.com', + 'Check this out!https://afterdot.com', 'start middle.com end', 'start middle.com/foo/bar end', @@ -122,6 +124,8 @@ describe('detectFacets', () => { ['https://newline2.com', 'https://newline2.com'], ], [['๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง '], ['https://middle.com', 'https://middle.com'], [' ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง']], + [['Check this out.'], ['https://afterdot.com', 'https://afterdot.com']], + [['Check this out!'], ['https://afterdot.com', 'https://afterdot.com']], [['start '], ['middle.com', 'https://middle.com'], [' end']], [