From 222aaf70beea520ff768400d5314d79b4b0f2ef1 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 18:59:08 -0600 Subject: [PATCH] fix(id-web): validate task_list start in parseDOM (#4100) --- pkgs/id/web/src/editor.test.ts | 57 ++++++++++++++++++++++++++++++++++ pkgs/id/web/src/editor.ts | 9 ++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/pkgs/id/web/src/editor.test.ts b/pkgs/id/web/src/editor.test.ts index 52a080a4f6..c68770f0a0 100644 --- a/pkgs/id/web/src/editor.test.ts +++ b/pkgs/id/web/src/editor.test.ts @@ -301,6 +301,63 @@ describe("ordered_list start parsing (#2005)", () => { }); }); +// ============================================================================ +// #4100: task_list parseDOM start parsing -- the
    rule reads its start +// through parseOrderedListStart, like ordered_list (#2005): only plain +// non-negative safe integers survive; everything else falls back to 1 +// instead of reaching the u64 markdown codec as a fraction/negative or a +// reinterpreted hex/scientific value. +// ============================================================================ + +describe("task_list start parsing (#4100)", () => { + const olGetAttrs = () => { + const rules = richSchema.nodes.task_list.spec.parseDOM ?? []; + const rule = rules.find((r) => r.tag === "ol"); + if (!rule || !("getAttrs" in rule) || typeof rule.getAttrs !== "function") { + throw new Error("task_list parseDOM has no ol getAttrs rule"); + } + return rule.getAttrs; + }; + + it.each([ + ["5", 5], + ["0", 0], + ["42", 42], + ])("preserves valid start=%s as order %i", (raw, expected) => { + const el = document.createElement("ol"); + el.classList.add("contains-task-list"); + el.setAttribute("start", raw); + expect(olGetAttrs()(el)).toEqual({ order: expected }); + }); + + it.each(["abc", "2.5", "0x10", "1e3", "", "-3", "9007199254740993"])( + "falls back to 1 for invalid start=%s", + (raw) => { + const el = document.createElement("ol"); + el.classList.add("contains-task-list"); + el.setAttribute("start", raw); + expect(olGetAttrs()(el)).toEqual({ order: 1 }); + }, + ); + + it("defaults order to 1 without a start attribute", () => { + const el = document.createElement("ol"); + el.classList.add("contains-task-list"); + expect(olGetAttrs()(el)).toEqual({ order: 1 }); + }); + + it("validates the start of a checkbox-detected ordered task list too", () => { + const el = document.createElement("ol"); + el.setAttribute("start", "2.5"); + const li = document.createElement("li"); + const checkbox = document.createElement("input"); + checkbox.setAttribute("type", "checkbox"); + li.appendChild(checkbox); + el.appendChild(li); + expect(olGetAttrs()(el)).toEqual({ order: 1 }); + }); +}); + describe("rawSchema", () => { it("has doc node type", () => { expect(rawSchema.nodes.doc).toBeDefined(); diff --git a/pkgs/id/web/src/editor.ts b/pkgs/id/web/src/editor.ts index 2489354dce..170c72ca29 100644 --- a/pkgs/id/web/src/editor.ts +++ b/pkgs/id/web/src/editor.ts @@ -209,11 +209,14 @@ export const richSchema = new Schema({ tag: "ol", getAttrs(dom) { // Match
      (ordered task list); - // its start is the list's order. + // its start is the list's order, read through the same + // validated parse as ordered_list (#4100; the raw el.start + // reflection admits fractional/negative/hex starts the u64 + // markdown codec cannot represent). const el = dom as HTMLOListElement; - if (el.classList.contains("contains-task-list")) return { order: el.start }; + if (el.classList.contains("contains-task-list")) return { order: parseOrderedListStart(el.getAttribute("start")) }; const firstLi = el.querySelector("li"); - if (firstLi?.querySelector('input[type="checkbox"]')) return { order: el.start }; + if (firstLi?.querySelector('input[type="checkbox"]')) return { order: parseOrderedListStart(el.getAttribute("start")) }; return false; }, },