Skip to content

Commit

Permalink
Fixing sanitizeHTML file to allow it being loaded into server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
berhalak committed Dec 19, 2024
1 parent 4c53590 commit 288ba24
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/client/ui/sanitizeHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export function sanitizeTutorialHTML(source: string | Node): string {
}

const defaultPurifier = createDOMPurifier();
defaultPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);

const tutorialPurifier = createDOMPurifier();
tutorialPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);
tutorialPurifier.addHook('uponSanitizeElement', handleSanitizeTutorialElement);

// If we are executed in a browser, we can add hooks to the purifiers to customize their behavior.
if (typeof window !== 'undefined') {
defaultPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);
tutorialPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);
tutorialPurifier.addHook('uponSanitizeElement', handleSanitizeTutorialElement);
}

function handleSanitizeAttribute(node: Element) {
if (!('target' in node)) { return; }
Expand Down

0 comments on commit 288ba24

Please sign in to comment.