Enhance occurrenceIndex validation in applyDashboardPatches to ensure it is a valid integer and within bounds

This commit is contained in:
Aadesh Kheria 2026-05-05 13:19:25 -07:00
parent 7e850dbe60
commit 7527bcfb9d

View File

@ -98,7 +98,11 @@ export function applyDashboardPatches(source: string, edits: DashboardPatchEdit[
let chosenIndex: number;
if (edit.occurrenceIndex != null) {
if (edit.occurrenceIndex < 0 || edit.occurrenceIndex >= matches.length) {
if (
!Number.isInteger(edit.occurrenceIndex)
|| edit.occurrenceIndex < 0
|| edit.occurrenceIndex >= matches.length
) {
failures.push({ index, reason: "not-found", oldTextPreview: preview });
return;
}