mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
fix(desktop): reject invalid task pointer escapes
This commit is contained in:
1 parent
6aa3898317
commit
361be4cb63
3 files changed
+25
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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) === ""
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user