Add share URL builders and embed format helpers for uploaded images.
Centralize clearnet/onion paths, delete links, and BBCode/Markdown/HTML output with unit tests and escape-html for safe HTML snippets.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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>'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user