0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { sanitizeMarkdown } from '../../site/src/utils/markdown';
|
|
|
|
describe('sanitizeMarkdown', () => {
|
|
const sampleMarkdown = `---
|
|
title: Test Document
|
|
author: Test Author
|
|
---
|
|
|
|
# Main Title
|
|
|
|
This is a paragraph with  and some text.
|
|
|
|
<!-- This is a comment -->
|
|
|
|
<div style="color: red;">Styled content</div>
|
|
|
|
\`\`\`javascript
|
|
console.log('code block');
|
|
\`\`\`
|
|
|
|
Here's some \`inline code\` and a [link](https://example.com).
|
|
|
|
<img src="test.jpg" alt="HTML image" />
|
|
|
|
|
|
Multiple newlines above.
|
|
`;
|
|
|
|
it('should sanitize markdown with sane defaults', () => {
|
|
const result = sanitizeMarkdown(sampleMarkdown);
|
|
|
|
expect(result).not.toContain('---');
|
|
expect(result).not.toContain('title: Test Document');
|
|
expect(result).not.toContain('author: Test Author');
|
|
|
|
expect(result).not.toContain('');
|
|
expect(result).not.toContain('<img src="test.jpg"');
|
|
|
|
expect(result).not.toContain('<!-- This is a comment -->');
|
|
|
|
expect(result).not.toContain('<div style="color: red;">');
|
|
expect(result).toContain('Styled content');
|
|
|
|
expect(result).toContain('console.log');
|
|
expect(result).toContain('```javascript');
|
|
expect(result).toContain('`inline code`');
|
|
expect(result).toContain('[link](https://example.com)');
|
|
|
|
expect(result).not.toMatch(/\n\n\n/);
|
|
expect(result).toMatch(/^# Main Title/);
|
|
});
|
|
|
|
it('should handle empty string', () => {
|
|
expect(sanitizeMarkdown('')).toBe('');
|
|
});
|
|
|
|
it('should handle null/undefined input', () => {
|
|
expect(sanitizeMarkdown(null as any)).toBe('');
|
|
expect(sanitizeMarkdown(undefined as any)).toBe('');
|
|
});
|
|
|
|
it('should handle non-string input', () => {
|
|
expect(sanitizeMarkdown(123 as any)).toBe('');
|
|
});
|
|
|
|
it('should handle TOML frontmatter', () => {
|
|
const tomlMarkdown = `+++
|
|
title = "Test"
|
|
+++
|
|
|
|
# Content`;
|
|
const result = sanitizeMarkdown(tomlMarkdown);
|
|
expect(result).not.toContain('+++');
|
|
expect(result).not.toContain('title = "Test"');
|
|
expect(result).toContain('# Content');
|
|
});
|
|
|
|
it('should preserve markdown formatting', () => {
|
|
const formattedMarkdown = `# Heading
|
|
|
|
**Bold text** and *italic text*
|
|
|
|
- List item 1
|
|
- List item 2
|
|
|
|
> Blockquote`;
|
|
|
|
const result = sanitizeMarkdown(formattedMarkdown);
|
|
expect(result).toContain('# Heading');
|
|
expect(result).toContain('**Bold text**');
|
|
expect(result).toContain('*italic text*');
|
|
expect(result).toContain('- List item 1');
|
|
expect(result).toContain('> Blockquote');
|
|
});
|
|
});
|