Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/icon pack/preview: fix an issue
Adorian Doranb6f183a897df
diff --git a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.spec.tsx b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.spec.tsxindex c39c5516a3..fe4348fb5e 100644--- a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.spec.tsx+++ b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.spec.tsx@@ -20,6 +20,11 @@ describe("resolveGlyph", () => {expect(resolveGlyph("")).toBe("");expect(resolveGlyph("bx-sushi")).toBe("bx-sushi");expect(resolveGlyph("\\zzzz")).toBe("\\zzzz");++ // An out-of-range code point (regex allows 6 hex digits) is left as-is, not passed to+ // String.fromCodePoint (which throws RangeError above U+10FFFF).+ expect(resolveGlyph("\\110000")).toBe("\\110000");+ expect(resolveGlyph("\\10ffff")).toBe(String.fromCodePoint(0x10ffff));});});diff --git a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsxindex 6838f1abb5..e577167461 100644--- a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx+++ b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx@@ -127,7 +127,9 @@ export function resolveGlyph(raw: string): string {const match = raw.match(/^\\u?([0-9a-fA-F]{2,6})$/);if (match) {const codePoint = parseInt(match[1], 16);- if (!Number.isNaN(codePoint)) return String.fromCodePoint(codePoint);+ // The regex admits up to 6 hex digits; guard the valid Unicode range so an out-of-range escape+ // (e.g. "\110000") isn't handed to String.fromCodePoint, which throws RangeError above U+10FFFF.+ if (!Number.isNaN(codePoint) && codePoint <= 0x10ffff) return String.fromCodePoint(codePoint);}return raw;}