File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ test('safeLinkHref', () => {
88 expect ( safeLinkHref ( 'javascript:void(0);' ) ) . toBeNull ( ) ;
99 expect ( safeLinkHref ( 'data:image/svg+xml;utf8,<svg></svg>' ) ) . toBeNull ( ) ;
1010 // for safety and consistency, it converts non-string input to string (just like window.location.href = 0)
11- expect ( safeLinkHref ( 0 as any ) ) . toBe ( 'http://localhost:3000/0' ) ;
12- expect ( safeLinkHref ( { } as any ) ) . toBe ( 'http://localhost:3000/[object%20Object]' ) ;
13- expect ( safeLinkHref ( null as any ) ) . toBe ( 'http://localhost:3000/null' ) ;
11+ expect ( safeLinkHref ( 0 ) ) . toBe ( 'http://localhost:3000/0' ) ;
12+ expect ( safeLinkHref ( { } ) ) . toBe ( 'http://localhost:3000/[object%20Object]' ) ;
13+ expect ( safeLinkHref ( null ) ) . toBe ( 'http://localhost:3000/null' ) ;
1414} ) ;
1515
1616test ( 'navigateToIframeLink' , ( ) => {
@@ -33,6 +33,10 @@ test('navigateToIframeLink', () => {
3333 expect ( assignSpy ) . toHaveBeenCalledWith ( 'http://localhost:3000/path' ) ;
3434 vi . clearAllMocks ( ) ;
3535
36+ navigateToIframeLink ( 123 , { } ) ; // input can be any type & any value
37+ expect ( assignSpy ) . toHaveBeenCalledWith ( 'http://localhost:3000/null' ) ;
38+ vi . clearAllMocks ( ) ;
39+
3640 // eslint-disable-next-line no-script-url
3741 navigateToIframeLink ( 'javascript:void(0);' , '_blank' ) ;
3842 expect ( openSpy ) . toHaveBeenCalledTimes ( 0 ) ;
Original file line number Diff line number Diff line change 11import { generateElemId , queryElemChildren } from '../utils/dom.ts' ;
22import { isDarkTheme } from '../utils.ts' ;
33
4- export function safeLinkHref ( link : string ) : string | null {
4+ // arguments can be any type & any value, they are from "message" event's data
5+ export function safeLinkHref ( link : any ) : string | null {
56 try {
67 const url = new URL ( `${ link } ` , window . location . href ) ;
78 if ( url . protocol !== 'http:' && url . protocol !== 'https:' ) {
@@ -15,7 +16,8 @@ export function safeLinkHref(link: string): string | null {
1516 }
1617}
1718
18- export function navigateToIframeLink ( unsafeLink : string , target : string | null ) {
19+ // arguments can be any type & any value, they are from "message" event's data
20+ export function navigateToIframeLink ( unsafeLink : any , target : any ) {
1921 const linkHref = safeLinkHref ( unsafeLink ) ;
2022 if ( linkHref === null ) return ;
2123 if ( target === '_blank' ) {
You can’t perform that action at this time.
0 commit comments