Skip to content
Open
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
13 changes: 9 additions & 4 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ function getSourceMeta(source) {
return SOURCE_META.default;
}

function highlightQuery(html, query) {
if (!html || !query || !query.trim()) return html || '';
function escapeHtml(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}

function highlightQuery(text, query) {
const safe = escapeHtml(text || '');
if (!query || !query.trim()) return safe;
try {
const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const re = new RegExp(`(${escaped})`, 'gi');
return html.replace(re, '<mark>$1</mark>');
return safe.replace(re, '<mark>$1</mark>');
} catch {
return html;
return safe;
}
}

Expand Down