Skip to content

Commit 21065e3

Browse files
authored
fix: URL_REG subdomain / top-level domain (#934)
Fixes https://sendbird.atlassian.net/browse/SBISSUE-14740 ``` // A subdomain has a hyphen 'https://send-bird.slack.com/archives/C065N4UQ77W/p1699931368643169?thread_ts=1699925671l395019&cid-Co65N4UQ77W', // with long top-level domain 'https://send.bird.business/archives/C065N4UQ77W/p1699931368643169?thread_ts=1699925671l395019&cid-Co65N4UQ77W', ``` couldn't be correctly checked by the URL_REG, so modified it a bit.
1 parent 37bbec4 commit 21065e3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/utils/__tests__/utils.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ describe('isURL', () => {
175175
// with the hash property
176176
'https://example.com/path/to/page.html?query=string#hash',
177177
'https://docs.google.com/document/d/19IccwdTIwNPJ_rGtsbi2Ft8dshaH4WiCXD5pder97VE/edit#heading=h.pve9ikkfqqzz',
178+
// A subdomain has a hyphen
179+
'https://send-bird.slack.com/archives/C065N4UQ77W/p1699931368643169?thread_ts=1699925671l395019&cid-Co65N4UQ77W',
180+
// with long top-level domain
181+
'https://send.bird.business/archives/C065N4UQ77W/p1699931368643169?thread_ts=1699925671l395019&cid-Co65N4UQ77W',
178182
];
179183
validURLs.forEach((url) => {
180184
expect(isUrl(url)).toBe(true);

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export const isMessageSentByMe = (
424424
!!(userId && message?.sender?.userId && userId === message.sender.userId)
425425
);
426426

427-
const URL_REG = /^((http|https):\/\/)?([a-z\d]+\.)+[a-z]{2,6}(\:[0-9]{1,5})?(\/[-a-zA-Z\d%_.~+&=]*)*(\?[;&a-zA-Z\d%_.~+=-]*)?(#\S*)?$/;
427+
const URL_REG = /^((http|https):\/\/)?([a-z\d-]+\.)+[a-z]{2,}(\:[0-9]{1,5})?(\/[-a-zA-Z\d%_.~+&=]*)*(\?[;&a-zA-Z\d%_.~+=-]*)?(#\S*)?$/;
428428
export const isUrl = (text: string): boolean => URL_REG.test(text);
429429

430430
const MENTION_TAG_REG = /\@\{.*?\}/i;

0 commit comments

Comments
 (0)