From 615899e9a9c3c7c0dd5c2a2114f867b1fd112404 Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Fri, 6 Mar 2026 13:27:40 -0800 Subject: [PATCH] Normalize fieldset legend text same as getLabel (dedup, strip Required) Legend text was saved to answers.json with duplicated text and "Required" suffix, causing pattern mismatches on future runs. Co-Authored-By: Claude Opus 4.6 --- lib/form_filler.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/form_filler.mjs b/lib/form_filler.mjs index d28785e..d2b67bf 100644 --- a/lib/form_filler.mjs +++ b/lib/form_filler.mjs @@ -411,7 +411,16 @@ Answer:`; // Fieldsets (radios and checkbox groups) for (const fs of await container.$$('fieldset')) { - const leg = await fs.$eval('legend', el => el.textContent.trim()).catch(() => ''); + const leg = await fs.$eval('legend', el => { + let raw = (el.textContent || '').replace(/\s+/g, ' ').replace(/\s*\*\s*$/, '').replace(/\s*Required\s*$/i, '').trim(); + if (raw.length > 8) { + for (let len = Math.ceil(raw.length / 2); len >= 4; len--) { + const candidate = raw.slice(0, len); + if (raw.startsWith(candidate + candidate)) { raw = candidate.trim(); break; } + } + } + return raw; + }).catch(() => ''); if (!leg) continue; const anyChecked = await fs.$('input:checked'); if (anyChecked) continue;