Skip to content

Commit

Permalink
escape html for external strings
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Oct 8, 2024
1 parent 9f0c460 commit 0c41d48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/tools/icon-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isFileExcalidraw,
warnDebug,
} from './utils'
import { escapeHTML } from './text-processing'

export interface IconPacks {
prefixToIconPack: { [prefix: string]: string }
Expand Down Expand Up @@ -133,7 +134,7 @@ export async function loadIconSVG(

if (!prefix) {
// No prefix, assume it's an emoji or text
return `<span class="omnisearch-result__icon--emoji">${name}</span>`
return `<span class="omnisearch-result__icon--emoji">${escapeHTML(name)}</span>`
}

const iconPackName = prefixToIconPack[prefix]
Expand Down
11 changes: 1 addition & 10 deletions src/tools/text-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ export class TextProcessor {
}
}

escapeHTML(html: string): string {
return html
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#039;')
}

/**
* Converts a list of strings to a list of words, using the \b word boundary.
* Used to find excerpts in a note body, or select which words to highlight.
Expand Down Expand Up @@ -200,7 +191,7 @@ export class TextProcessor {
}
}

function escapeHTML(html: string): string {
export function escapeHTML(html: string): string {
return html
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
Expand Down

0 comments on commit 0c41d48

Please sign in to comment.