Skip to content

Commit aea97eb

Browse files
authored
hotfix: isURL can't catch & included URL (#520)
### Description Of Changes #509 related. A URL including `&` charactor should be filtered by URL_REG too.
1 parent 29daf15 commit aea97eb

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/utils/__tests__/utils.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('isURL', () => {
4343
'https://example.com/path/to/page.html?query=string',
4444
'www.example.com/path/to/page.html?query=string',
4545
'example.com/path/to/page.html?query=string',
46+
'https://www.amazon.com/Hacker-Playbook-Practical-Penetration-Testing/dp/1494932636/ref=sr_1_5?crid=1IKVPDXYF5NQG&keywords=hacker+guide&qid=1681333238&sprefix=hacker+guid%2Caps%2C148&sr=8-5'
4647
]
4748
validURLs.forEach((url) => {
4849
expect(isUrl(url)).toBe(true);

src/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const isMessageSentByMe = (userId: string, message: UserMessage | FileMes
258258
(userId && message?.sender?.userId) && userId === message.sender.userId
259259
);
260260

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

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

0 commit comments

Comments
 (0)