Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(snippets): handle nullish and partial settings in getDictionaryHintWords (#1671) (#1672)
Henry Su7de403ece65e
diff --git a/src/utils/snippets.ts b/src/utils/snippets.tsindex e82e7e20e..39061c8bc 100644--- a/src/utils/snippets.ts+++ b/src/utils/snippets.ts@@ -76,10 +76,16 @@ export function expandSnippets(text: string, snippets: Snippet[]): string {* Dictionary words plus snippet triggers — the hint list fed to the STT* prompt and cleanup-model dictionary suffix so triggers survive both.*/-export function getDictionaryHintWords(settings: {- customDictionary: string[];- snippets: Snippet[];-}): string[] {- if (settings.snippets.length === 0) return settings.customDictionary;- return [...settings.customDictionary, ...settings.snippets.map((s) => s.trigger)];+export function getDictionaryHintWords(settings?: {+ customDictionary?: string[] | null;+ snippets?: Snippet[] | null;+} | null): string[] {+ const dictionary = Array.isArray(settings?.customDictionary) ? settings.customDictionary : [];+ const snippets = Array.isArray(settings?.snippets) ? settings.snippets : [];+ if (snippets.length === 0) return [...dictionary];++ const triggers = snippets+ .map((s) => s?.trigger)+ .filter((t): t is string => typeof t === "string" && t.length > 0);+ return [...dictionary, ...triggers];}diff --git a/test/utils/snippets.test.js b/test/utils/snippets.test.jsindex 2fdd98092..543994fcc 100644--- a/test/utils/snippets.test.js+++ b/test/utils/snippets.test.js@@ -1,7 +1,7 @@const test = require("node:test");const assert = require("node:assert/strict");-const { expandSnippets } = require("../../src/utils/snippets.ts");+const { expandSnippets, getDictionaryHintWords } = require("../../src/utils/snippets.ts");test("expands a trigger containing Turkish capital İ", () => {const snippets = [{ trigger: "İmza", replacement: "Best regards,\nUmut" }];@@ -75,3 +75,52 @@ test("multiple occurrences and unmatched text are preserved", () => {const snippets = [{ trigger: "İmza", replacement: "X" }];assert.equal(expandSnippets("İmza and imza, done", snippets), "X and X, done");});++test("getDictionaryHintWords returns empty list on nullish, empty, or partial settings", () => {+ assert.deepEqual(getDictionaryHintWords(null), []);+ assert.deepEqual(getDictionaryHintWords(undefined), []);+ assert.deepEqual(getDictionaryHintWords({}), []);+ assert.deepEqual(getDictionaryHintWords({ customDictionary: null }), []);+ assert.deepEqual(getDictionaryHintWords({ snippets: null }), []);+ assert.deepEqual(getDictionaryHintWords({ customDictionary: null, snippets: null }), []);+});++test("getDictionaryHintWords preserves customDictionary when snippets are absent or empty", () => {+ const customDictionary = ["OpenWhispr", "Supabase"];+ const result = getDictionaryHintWords({ customDictionary });+ assert.deepEqual(result, ["OpenWhispr", "Supabase"]);+ // Must return a fresh array, not the input reference+ assert.notEqual(result, customDictionary);++ const emptySnippetsResult = getDictionaryHintWords({ customDictionary, snippets: [] });+ assert.deepEqual(emptySnippetsResult, ["OpenWhispr", "Supabase"]);+ assert.notEqual(emptySnippetsResult, customDictionary);+});++test("getDictionaryHintWords extracts triggers when customDictionary is absent or empty", () => {+ const snippets = [+ { trigger: "my cal", replacement: "cal.com/me" },+ { trigger: "zoom link", replacement: "zoom.us/j/123" },+ ];+ assert.deepEqual(getDictionaryHintWords({ snippets }), ["my cal", "zoom link"]);+ assert.deepEqual(getDictionaryHintWords({ customDictionary: [], snippets }), [+ "my cal",+ "zoom link",+ ]);+});++test("getDictionaryHintWords combines dictionary words and snippet triggers safely", () => {+ const settings = {+ customDictionary: ["OpenWhispr", "Supabase"],+ snippets: [+ { trigger: "my cal", replacement: "cal.com/me" },+ { trigger: "zoom link", replacement: "zoom.us/j/123" },+ ],+ };+ assert.deepEqual(getDictionaryHintWords(settings), [+ "OpenWhispr",+ "Supabase",+ "my cal",+ "zoom link",+ ]);+});