diff --git a/src/helpers/sttConfigPolicy.js b/src/helpers/sttConfigPolicy.js index 8eca2bacd..ae80713bc 100644 --- a/src/helpers/sttConfigPolicy.js +++ b/src/helpers/sttConfigPolicy.js @@ -5,8 +5,12 @@ // awaited fetch stalls on auth resolution for seconds and then changes // nothing (#1673). export function needsSttConfigBeforeStart(settings) { - const s = settings || {}; + const s = settings && typeof settings === "object" ? settings : {}; if (s.useLocalWhisper) return false; - if (s.cloudTranscriptionMode !== "openwhispr") return false; + const cloudMode = + typeof s.cloudTranscriptionMode === "string" + ? s.cloudTranscriptionMode.trim().toLowerCase() + : ""; + if (cloudMode !== "openwhispr") return false; return !!s.isSignedIn; } diff --git a/test/helpers/sttConfigPolicy.test.js b/test/helpers/sttConfigPolicy.test.js index aa538f2f7..76165e112 100644 --- a/test/helpers/sttConfigPolicy.test.js +++ b/test/helpers/sttConfigPolicy.test.js @@ -62,6 +62,21 @@ describe("needsSttConfigBeforeStart", () => { test("missing settings fail open to a non-blocking start", async () => { const { needsSttConfigBeforeStart } = await loadPolicy(); assert.equal(needsSttConfigBeforeStart(null), false); + assert.equal(needsSttConfigBeforeStart(undefined), false); + assert.equal(needsSttConfigBeforeStart(123), false); + assert.equal(needsSttConfigBeforeStart(""), false); assert.equal(needsSttConfigBeforeStart({}), false); }); + + test("normalizes mixed-case and whitespace in cloudTranscriptionMode", async () => { + const { needsSttConfigBeforeStart } = await loadPolicy(); + assert.equal( + needsSttConfigBeforeStart({ + useLocalWhisper: false, + cloudTranscriptionMode: " OpenWhispr ", + isSignedIn: true, + }), + true + ); + }); });