snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
35
web_src/js/markup/render-iframe.test.ts
Normal file
35
web_src/js/markup/render-iframe.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {navigateToIframeLink} from './render-iframe.ts';
|
||||
import {captureNavigations} from '../utils/testhelper.ts';
|
||||
|
||||
describe('navigateToIframeLink', () => {
|
||||
test('safe links', () => {
|
||||
const navigations = captureNavigations();
|
||||
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
|
||||
navigateToIframeLink('http://example.com', '_blank');
|
||||
expect(openSpy).toHaveBeenCalledWith('http://example.com/', '_blank', 'noopener,noreferrer');
|
||||
navigateToIframeLink('https://example.com', '_self');
|
||||
expect(navigations.at(-1)!.url).toEqual('https://example.com/');
|
||||
navigateToIframeLink('https://example.com', null);
|
||||
expect(navigations.at(-1)!.url).toEqual('https://example.com/');
|
||||
navigateToIframeLink('/path', '');
|
||||
expect(navigations.at(-1)!.url).toEqual(`${window.location.origin}/path`);
|
||||
// input can be any type & any value, keep the same behavior as `window.location.href = 0`
|
||||
navigateToIframeLink(0, {});
|
||||
expect(navigations.at(-1)!.url).toEqual(`${window.location.origin}/0`);
|
||||
expect(navigations).toHaveLength(4);
|
||||
openSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('unsafe links', () => {
|
||||
const navigations = captureNavigations();
|
||||
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
// eslint-disable-next-line no-script-url -- the test asserts that javascript: links are rejected
|
||||
navigateToIframeLink('javascript:void(0);', '_blank');
|
||||
navigateToIframeLink('data:image/svg+xml;utf8,<svg></svg>', '');
|
||||
expect(openSpy).toHaveBeenCalledTimes(0);
|
||||
expect(navigations).toEqual([]);
|
||||
openSpy.mockRestore();
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user