File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
src/modules/Message/utils/tokens Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments