Skip to content

Commit 4819f65

Browse files
committed
fine tune types
1 parent 67cb794 commit 4819f65

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

web_src/js/markup/render-iframe.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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

1616
test('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);

web_src/js/markup/render-iframe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {generateElemId, queryElemChildren} from '../utils/dom.ts';
22
import {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') {

0 commit comments

Comments
 (0)