Centralize clearnet/onion paths, delete links, and BBCode/Markdown/HTML output with unit tests and escape-html for safe HTML snippets.
23 lines
820 B
TypeScript
23 lines
820 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { buildHtmlLink } from '@/utils/share/buildHtmlLink';
|
|
|
|
describe('buildHtmlLink', () => {
|
|
it('builds an anchor with escaped href and label', () => {
|
|
expect(buildHtmlLink('photo.jpg', 'https://example.com/v/1#key')).toBe(
|
|
'<a href="https://example.com/v/1#key">photo.jpg</a>'
|
|
);
|
|
});
|
|
|
|
it('escapes HTML in link label', () => {
|
|
expect(buildHtmlLink('<script>alert(1)</script>', 'https://example.com/v/1')).toBe(
|
|
'<a href="https://example.com/v/1"><script>alert(1)</script></a>'
|
|
);
|
|
});
|
|
|
|
it('escapes quotes in href', () => {
|
|
expect(buildHtmlLink('label', 'https://example.com/x" y')).toBe(
|
|
'<a href="https://example.com/x" y">label</a>'
|
|
);
|
|
});
|
|
});
|