From 361be4cb630f54820f1b2702df0982e1dc7f81de Mon Sep 17 00:00:00 2001 From: Nianze Wu Date: Sun, 15 Nov 2026 14:42:07 +0800 Subject: [PATCH] fix(desktop): reject invalid task pointer escapes --- docs/desktop-application-tasks.md | 3 ++- src/domain/desktop/appTask.ts | 2 ++ src/domain/desktop/appTaskChecks.test.ts | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/desktop-application-tasks.md b/docs/desktop-application-tasks.md index b29cefb683..a9726bcf0e 100644 --- a/docs/desktop-application-tasks.md +++ b/docs/desktop-application-tasks.md @@ -552,7 +552,8 @@ The rules both evaluators follow: - Equality is JSON equality: numbers by value, never a boolean for a number, objects by their keys whatever their order, arrays in order. - Pointers follow RFC 6901 (`~1` for `/`, `~0` for `~`) and must start with - `/`; on an array a segment may be a selector, below. Key files read as + `/`. Other `~` sequences are rejected, including within a selector. On an + array a segment may be a selector, below. Key files read as `{"groups": {"GROUP": {"KEY": "VALUE"}}}`, so a setting is `/groups/GROUP/KEY`; XML as `{"root": {"name", "attributes", "children"}}`; SQLite as `{"tables": {"TABLE": {"columns", "rows"}}}`; a zip archive as diff --git a/src/domain/desktop/appTask.ts b/src/domain/desktop/appTask.ts index aca791a75c..793023b49b 100644 --- a/src/domain/desktop/appTask.ts +++ b/src/domain/desktop/appTask.ts @@ -292,6 +292,8 @@ const pointerProblem = (check: PointerCheck): string | undefined => { : "the empty pointer names the whole file; point at the value that changed"; if (!check.pointer.startsWith("/")) return `pointer ${JSON.stringify(check.pointer)} must start with /`; + if (/~(?![01])/u.test(check.pointer)) + return `pointer ${JSON.stringify(check.pointer)} uses an invalid escape; use ~0 or ~1 for ~ or /`; return check.kind === "text_contains" && check.normalize_whitespace === true && collapseWhitespace(check.value) === "" diff --git a/src/domain/desktop/appTaskChecks.test.ts b/src/domain/desktop/appTaskChecks.test.ts index fb6b076d05..c7b4477cf2 100644 --- a/src/domain/desktop/appTaskChecks.test.ts +++ b/src/domain/desktop/appTaskChecks.test.ts @@ -1084,6 +1084,27 @@ describe("evaluateTaskChecks whole text", () => { }); describe("parseDesktopTask", () => { + it.each(["/value~2", "/tail~", "/[name=London~Bridge]/value"])( + "rejects an invalid JSON pointer escape in %s", + (pointer) => { + expect( + task([{ kind: "value_absent", file: "a", pointer }]), + ).toMatchObject({ + ok: false, + error: expect.stringContaining("~0 or ~1"), + }); + }, + ); + + it.each(["/value~02", "/tail~0", "/[name=London~0Bridge]/a~1b"])( + "accepts a valid JSON pointer escape in %s", + (pointer) => { + expect( + task([{ kind: "value_absent", file: "a", pointer }]), + ).toMatchObject({ ok: true }); + }, + ); + it("settles ids and keeps the prompt trimmed", () => { const parsed = parseDesktopTask({ name: "add-milk",