import { describe, it, expect } from 'vitest';
import {
sanitizeHtml,
decodeHtmlEntities,
renderInlineMarkdown,
parseJournalMarkdown,
serializeJournalMarkdown,
} from '../journal';
/**
* The previous sanitizer was a denylist: strip `'],
])('renders %s links as plain text instead of an anchor', (_name, url) => {
const html = renderInlineMarkdown(`[click me](${url})`);
// The label survives, the URL does not become a link. A stray `)` may be
// left over because the link pattern stops at the first closing paren —
// pre-existing behaviour, and harmless as text.
expect(html).toContain('click me');
expect(html).not.toContain(' {
const html = renderInlineMarkdown('[x](" onmouseover=alert(1) x=")');
expect(html).not.toContain('onmouseover=alert(1)');
});
it('does not let a label inject markup', () => {
const html = renderInlineMarkdown('[
](https://example.com)');
expect(html).not.toContain('
{
it('does not accumulate entities when parsing and serializing repeatedly', () => {
const source = '---\ntitle: "T"\n---\n\nAngle < bracket & ampersand "quoted"\n';
const once = serializeJournalMarkdown(parseJournalMarkdown(source));
const twice = serializeJournalMarkdown(parseJournalMarkdown(once));
expect(once).toContain('Angle < bracket & ampersand "quoted"');
expect(twice).toBe(once);
});
it('decodes exactly what sanitizeHtml encodes', () => {
const raw = `5 & 6 don't`;
expect(decodeHtmlEntities(sanitizeHtml(raw))).toBe(raw);
});
});