Skip to content

Commit 5353f98

Browse files
chohongmAhyoungRyu
authored andcommitted
fix: Fixed a bug where spreading matchAll() result not working with built files (#1143)
discussion: https://sendbird.slack.com/archives/G01290GCDCN/p1718676602610299
1 parent 61190e8 commit 5353f98

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { asSafeURL } from '../asSafeURL';
2+
3+
describe('asSafeURL', () => {
4+
test('should return the same URL if it is already safe', () => {
5+
expect(asSafeURL('http://example.com')).toBe('http://example.com');
6+
expect(asSafeURL('https://example.com')).toBe('https://example.com');
7+
});
8+
9+
test('should return a safe URL if it is not safe', () => {
10+
expect(asSafeURL('mailto:[email protected]')).toBe('#');
11+
// eslint-disable-next-line no-script-url
12+
expect(asSafeURL('javascript:alert(1)')).toBe('#');
13+
expect(asSafeURL('javascript%3Aalert%281%29')).toBe('#');
14+
expect(asSafeURL('data:text/html;base64,ABCDE==')).toBe('#');
15+
});
16+
17+
test('should append a https:// protocol to the URL if it is missing', () => {
18+
expect(asSafeURL('example.com')).toBe('https://example.com');
19+
});
20+
});

src/modules/Message/utils/tokens/tokenize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function splitTokensWithMarkdowns(tokens: Token[]): Token[] {
116116
}
117117
const rawStr = token.value;
118118
// @ts-ignore
119-
const matches = [...rawStr.matchAll(MarkdownRegex)];
119+
const matches = Array.from(rawStr.matchAll(MarkdownRegex));
120120
const allMatches = matches.map((value) => {
121121
const text = value[0];
122122
const start = value.index ?? 0;

0 commit comments

Comments
 (0)