From 235ae586998661621fe1c519a19883ebc990f24a Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2026 22:41:12 +0000 Subject: [PATCH] fix(record): Safely query sibling radio buttons using getElementsByName --- packages/rrweb/src/record/observer.ts | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/rrweb/src/record/observer.ts b/packages/rrweb/src/record/observer.ts index 41b053a73d..0dd8d9b089 100644 --- a/packages/rrweb/src/record/observer.ts +++ b/packages/rrweb/src/record/observer.ts @@ -558,25 +558,29 @@ function initInputObserver({ // the other radios with the same name attribute will be unchecked. const name: string | undefined = (target as HTMLInputElement).name; if (type === 'radio' && name && isChecked) { - doc - .querySelectorAll(`input[type="radio"][name="${name}"]`) - .forEach((el) => { - if (el !== target) { - const text = maskInputValue({ - // share mask behavior of `target` - isMasked: forceMask, - element: el as HTMLInputElement, - value: getInputValue(el as HTMLInputElement, tagName, type), - maskInputFn, - }); - cbWithDedup( - el, - userTriggeredOnInput - ? { text, isChecked: !isChecked, userTriggered: false } - : { text, isChecked: !isChecked }, - ); - } - }); + // Avoid building a CSS selector from the name: names can contain + // characters (e.g. quotes) that make the selector invalid. + Array.from(doc.getElementsByName(name)).forEach((el) => { + if ( + el !== target && + el.tagName.toLowerCase() === 'input' && + (el as HTMLInputElement).type?.toLowerCase() === 'radio' + ) { + const text = maskInputValue({ + // share mask behavior of `target` + isMasked: forceMask, + element: el as HTMLInputElement, + value: getInputValue(el as HTMLInputElement, tagName, type), + maskInputFn, + }); + cbWithDedup( + el, + userTriggeredOnInput + ? { text, isChecked: !isChecked, userTriggered: false } + : { text, isChecked: !isChecked }, + ); + } + }); } } function cbWithDedup(target: EventTarget, v: inputValue) {