Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/utils/url-link-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function convertUrlsToLinks(text) {

// Extract code blocks and replace with placeholders
while ((codeMatch = codeBlockRegex.exec(text)) !== null) {
const placeholder = `<[CODE_BLOCK_${codeIndex}]>`;
const placeholder = `__QRYPTCHAT_CODE_BLOCK_${codeIndex}__`;
const codeContent = codeMatch[1];
codeBlocks.push(`<pre><code>${escapeHtml(codeContent)}</code></pre>`);
textWithPlaceholders = textWithPlaceholders.replace(codeMatch[0], placeholder);
Expand Down Expand Up @@ -87,7 +87,7 @@ export function convertUrlsToLinks(text) {

// Restore code blocks from placeholders
codeBlocks.forEach((codeBlock, index) => {
const placeholder = `<[CODE_BLOCK_${index}]>`;
const placeholder = `__QRYPTCHAT_CODE_BLOCK_${index}__`;
result = result.replace(placeholder, codeBlock);
});

Expand Down
22 changes: 22 additions & 0 deletions src/lib/utils/url-link-converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,26 @@ describe('convertUrlsToLinks', () => {
expect(html).toContain('href="https://example.com/search?a=1&amp;b=2"');
expect(html).toContain('>https://example.com/search?a=1&amp;b=2</a>');
});

it('renders fenced code blocks instead of escaped placeholders', () => {
const html = convertUrlsToLinks('Before\n```const value = 1;\n```\nAfter');

expect(html).toContain('<pre><code>const value = 1;\n</code></pre>');
expect(html).not.toContain('CODE_BLOCK');
expect(html).not.toContain('&lt;[CODE_BLOCK_0]&gt;');
});

it('does not linkify URLs inside fenced code blocks', () => {
const html = convertUrlsToLinks('```https://example.com/search?a=1&b=2```');

expect(html).toContain('<pre><code>https://example.com/search?a=1&amp;b=2</code></pre>');
expect(html).not.toContain('<a href=');
});

it('escapes HTML inside fenced code blocks', () => {
const html = convertUrlsToLinks('```<script>alert("x")</script>```');

expect(html).toContain('&lt;script&gt;alert(&quot;x&quot;)&lt;/script&gt;');
expect(html).not.toContain('<script>');
});
});
Loading