Skip to content

Commit

Permalink
fix: Fixed a bug where spreading matchAll() result not working with b…
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcho authored and AhyoungRyu committed Jun 20, 2024
1 parent 61190e8 commit 5353f98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/modules/Message/utils/tokens/__tests__/asSafeUrl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { asSafeURL } from '../asSafeURL';

describe('asSafeURL', () => {
test('should return the same URL if it is already safe', () => {
expect(asSafeURL('http:https://example.com')).toBe('http:https://example.com');
expect(asSafeURL('https://example.com')).toBe('https://example.com');
});

test('should return a safe URL if it is not safe', () => {
expect(asSafeURL('mailto:[email protected]')).toBe('#');
// eslint-disable-next-line no-script-url
expect(asSafeURL('javascript:alert(1)')).toBe('#');
expect(asSafeURL('javascript%3Aalert%281%29')).toBe('#');
expect(asSafeURL('data:text/html;base64,ABCDE==')).toBe('#');
});

test('should append a https:// protocol to the URL if it is missing', () => {
expect(asSafeURL('example.com')).toBe('https://example.com');
});
});
2 changes: 1 addition & 1 deletion src/modules/Message/utils/tokens/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function splitTokensWithMarkdowns(tokens: Token[]): Token[] {
}
const rawStr = token.value;
// @ts-ignore
const matches = [...rawStr.matchAll(MarkdownRegex)];
const matches = Array.from(rawStr.matchAll(MarkdownRegex));
const allMatches = matches.map((value) => {
const text = value[0];
const start = value.index ?? 0;
Expand Down

0 comments on commit 5353f98

Please sign in to comment.