Skip to content

Commit

Permalink
docs: escape search results (#8873)
Browse files Browse the repository at this point in the history
closes #8856
  • Loading branch information
gtm-nayan authored Feb 3, 2023
1 parent fafe7d5 commit fa31965
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sites/kit.svelte.dev/src/lib/search/SearchResultList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
const dispatch = createEventDispatcher();
/** @param {string} text */
function escape(text) {
return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
/**
* @param {string} content
* @param {string} query
*/
function excerpt(content, query) {
const index = content.toLowerCase().indexOf(query.toLowerCase());
if (index === -1) {
return content.slice(0, 100);
return escape(content.slice(0, 100));
}
const prefix = index > 20 ? `${content.slice(index - 15, index)}` : content.slice(0, index);
Expand All @@ -34,7 +39,7 @@
</script>

<ul>
{#each results as result, i}
{#each results as result (result.href)}
<li>
<a
data-sveltekit-preload-data
Expand Down

0 comments on commit fa31965

Please sign in to comment.