From 4146915a3339e0381f330f2e652c79f08826d016 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 5 Dec 2022 00:15:17 +0000 Subject: [PATCH] fix: decode numerically encoded html entities in text --- composables/content.ts | 4 +++- tests/__snapshots__/html-parse.test.ts.snap | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composables/content.ts b/composables/content.ts index b8b81ed3..97c66e9c 100644 --- a/composables/content.ts +++ b/composables/content.ts @@ -72,7 +72,9 @@ export function parseMastodonHTML(html: string, customEmojis: Record$1'], [/~~(.*?)~~/g, '$1'], [/`([^`]+?)`/g, '$1'], - ] as const + [/&#(\d+);/g, (_: string, dec: string) => String.fromCharCode(Number(dec))], + ] as any + for (const [re, replacement] of replacements) { for (const match of node.value.matchAll(re)) { if (node.loc) { diff --git a/tests/__snapshots__/html-parse.test.ts.snap b/tests/__snapshots__/html-parse.test.ts.snap index ffcd8d65..55208cf5 100644 --- a/tests/__snapshots__/html-parse.test.ts.snap +++ b/tests/__snapshots__/html-parse.test.ts.snap @@ -1,7 +1,7 @@ // Vitest Snapshot v1 exports[`html-parse > code frame > html 1`] = ` -"

Testing code block

import { useMouse, usePreferredDark } from '@vueuse/core'
+"

Testing code block

import { useMouse, usePreferredDark } from '@vueuse/core'
 // tracks mouse position
 const { x, y } = useMouse()
 // is the user prefers dark theme
@@ -12,7 +12,7 @@ exports[`html-parse > code frame > text 1`] = `
 "Testing code block
 
 \`\`\`ts
-import { useMouse, usePreferredDark } from '@vueuse/core'
+import { useMouse, usePreferredDark } from '@vueuse/core'
 // tracks mouse position
 const { x, y } = useMouse()
 // is the user prefers dark theme