Skip to content

Commit 758d938

Browse files
committed
fix: don't parse @user.name as URLs
Currently, the period in a user name will make the parser assume it is a URL. This commit adds a negative lookbehind to the regex parsing URLs to avoid doing so, by assuming that `@\w+\.?\w*` matches user names.
1 parent 2c18a2a commit 758d938

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

package/src/components/Message/MessageSimple/utils/parseLinks.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ getstream.io
108108

109109
expect(result).toHaveLength(0);
110110
});
111+
112+
it.each([['@user'], ['@user.name']])('does not parse %p as a URL', (input) => {
113+
const result = parseLinksFromText(input);
114+
115+
expect(result).toHaveLength(0);
116+
});
111117
});

package/src/components/Message/MessageSimple/utils/parseLinks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
const emailUserName = '[\\w+\\.~$_-]+';
1010
const schema = `(\\w{2,15}:\\/\\/)`;
1111
// something.tld OR 123.123.123.123
12-
const domain = `((?:\\w+\\.[a-zA-Z]+)+(?:[^:\\/\\s]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))`;
12+
const userName = '^@\\w+\\.?\\w*';
13+
const domain = `((?:\\w+\\.[a-zA-Z]+(?<!${userName}))+(?:[^:\\/\\s]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))`;
1314
const port = `(:[0-9]{1,5})`;
1415
const path = `((?:\\/)?[^?\\s]+)`;
1516
const queryString = `(\\?[^#\\s]+)`;

0 commit comments

Comments
 (0)