From ff978a8df3284e2fa0900e1dfc1ec047a7d79834 Mon Sep 17 00:00:00 2001 From: saurabhhhcodes Date: Mon, 20 Jul 2026 16:32:27 +0530 Subject: [PATCH] fix: guard participantNameFromCandidate against nullish candidate (#803) --- src/participantDetection.test.ts | 5 +++++ src/participantDetection.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/participantDetection.test.ts b/src/participantDetection.test.ts index 9d959f1d..ea2ca3ca 100644 --- a/src/participantDetection.test.ts +++ b/src/participantDetection.test.ts @@ -101,3 +101,8 @@ test("case-insensitive control labels are rejected", () => { assert.equal(participantNameFromCandidate({ selfName: "mute" }), null); assert.equal(participantNameFromCandidate({ selfName: "Camera Off" }), null); }); + +test("nullish candidate does not throw", () => { + assert.equal(participantNameFromCandidate(null), null); + assert.equal(participantNameFromCandidate(undefined), null); +}); diff --git a/src/participantDetection.ts b/src/participantDetection.ts index adfe50d1..d5c0c2cb 100644 --- a/src/participantDetection.ts +++ b/src/participantDetection.ts @@ -47,7 +47,11 @@ const LOWERCASE_EXCLUDED_LABELS = new Set( Array.from(EXCLUDED_PARTICIPANT_LABELS).map((label) => label.toLowerCase()), ); -export function participantNameFromCandidate(candidate: ParticipantNameCandidate): string | null { +export function participantNameFromCandidate( + candidate: ParticipantNameCandidate | null | undefined, +): string | null { + if (!candidate) return null; + const selfName = cleanText(candidate.selfName || ""); const text = stripExcludedLabels(candidate.text || ""); const ariaLabel = cleanText(candidate.ariaLabel || "");