A board's name is a name: the create door validates it, and the list is all strings (#1506) #1581

Merged
jaylouisw merged 1 commit from fix/1116-0136 into main 2026-11-16 01:53:12 +00:00
Owner

Fixes #1506

POST /api/topologies took the id from a JSON body and stored it unexamined, so {"id":123} set a NUMBER map key that no URL could reach, {"id":{"a":1}} wrote _object_Object_-<hash>.json and put an object in the list of ids, {"id":"."} wrote ..json, and a 400-character name was acknowledged with 201 and then failed every save with ENOENT behind a console.error.

boardIdProblem() now states the rule once, next to the file-name derivation that depends on it: a caller-chosen name is a string, non-empty after trimming, at most 128 characters (so <sanitised>-<hash>.json stays inside NAME_MAX), free of control characters, and not . or ... A refusal is 400 {"error": �, "field": "id"} naming the rule that was broken. An absent, null or empty id still means "make me one". GET /api/topologies returns only string keys.

test/board-id-is-a-name.test.js, 65 passed / 0 failed; against the old handler 32 of those 65 fail (nine refused shapes all answered 201, the list held a number, a boolean, an object, an array and ..).

Full suite 261 suites / 9503 assertions / 0 failed; syntax 331 files; check-control-bytes clean; api-errors 13/13, server-persistence 13/13, persistence 27/27, api-config-door 24/24, api-change-clock 12/12.

Fixes #1506 `POST /api/topologies` took the id from a JSON body and stored it unexamined, so `{"id":123}` set a NUMBER map key that no URL could reach, `{"id":{"a":1}}` wrote `_object_Object_-<hash>.json` and put an object in the list of ids, `{"id":"."}` wrote `..json`, and a 400-character name was acknowledged with 201 and then failed every save with ENOENT behind a console.error. `boardIdProblem()` now states the rule once, next to the file-name derivation that depends on it: a caller-chosen name is a string, non-empty after trimming, at most 128 characters (so `<sanitised>-<hash>.json` stays inside NAME_MAX), free of control characters, and not `.` or `..`. A refusal is `400 {"error": �, "field": "id"}` naming the rule that was broken. An absent, null or empty id still means "make me one". `GET /api/topologies` returns only string keys. test/board-id-is-a-name.test.js, **65 passed / 0 failed**; against the old handler 32 of those 65 fail (nine refused shapes all answered 201, the list held a number, a boolean, an object, an array and `..`). Full suite **261 suites / 9503 assertions / 0 failed**; syntax 331 files; check-control-bytes clean; api-errors 13/13, server-persistence 13/13, persistence 27/27, api-config-door 24/24, api-change-clock 12/12.
A board's name is a name: the create door validates it, and the list is all strings (#1506)
Some checks failed
CI / Classify the change (pull_request) Successful in 17s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 21s
CI / Docker build (pull_request) Failing after 12m25s
CI / Server smoke test (pull_request) Failing after 12m29s
CI / Test (Node 22) (pull_request) Failing after 12m35s
CI / Test (Node 20) (pull_request) Failing after 12m41s
CI / Test (Node 18) (pull_request) Failing after 12m45s
4218af5710
`POST /api/topologies` took the id from a JSON body, which is not a URL, and stored
it unexamined. Three kinds of board could be created that nothing downstream could
honour:

  {"id": 123}          a NUMBER map key, 123.json written, and GET /api/topologies/123
                       404s - every lookup builds its key from a URL segment, a string
  {"id": {"a": 1}}     `_object_Object_-<hash>.json`, and an object in the list of ids
  {"id": "."}          `..json`, i.e. a file named after a directory

and a 400-character name was acknowledged with 201 and then failed every save with
ENOENT, with a console.error as the only signal. The list endpoint meanwhile handed
out numbers, booleans and objects, so "list the boards" was not a list of names.

Now `boardIdProblem()` states the rule once, where the file name is derived from it:
a caller-chosen name is a string, non-empty after trimming, at most 128 characters
(which keeps `<sanitised>-<hash>.json` inside NAME_MAX), free of control characters,
and not `.` or `..`. A refusal is `400 {"error": ..., "field": "id"}` and the message
names the rule that was broken, not "invalid id". An absent, null or empty id still
means "make me one", which is what the client asks for. `GET /api/topologies` returns
only string keys.

The control-character test is a code-point loop rather than a character class: a class
holding a literal NUL is a collapse waiting to happen in the next scripted edit, and
check-control-bytes.js was right to refuse the first version of it.

test/board-id-is-a-name.test.js, 65 checks: nine refused shapes each get a 400 whose
message names the rule; a refused create changes nothing and writes no file; the list
is all strings and holds none of the refused names; `{}`, `{"id":""}`, `null` and no
body still generate a name; five accepted names (including `a b`, `a/b`, `Board #1`
and 128 characters) are reachable by the name they were created with and creating one
twice is idempotent; every file name is inside NAME_MAX and every saved board records
a string name; and after a restart the 128-character board and the one with a space
are still listed and readable. Against the old handler, 32 of those 65 failed.

Full suite 261 suites / 9503 assertions / 0 failed. Syntax 331 files.
jaylouisw force-pushed fix/1116-0136 from 4218af5710
Some checks failed
CI / Classify the change (pull_request) Successful in 17s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 21s
CI / Docker build (pull_request) Failing after 12m25s
CI / Server smoke test (pull_request) Failing after 12m29s
CI / Test (Node 22) (pull_request) Failing after 12m35s
CI / Test (Node 20) (pull_request) Failing after 12m41s
CI / Test (Node 18) (pull_request) Failing after 12m45s
to 2154f08491
Some checks failed
CI / Classify the change (pull_request) Successful in 18s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 19s
CI / Docker build (pull_request) Successful in 39s
CI / Server smoke test (pull_request) Failing after 11m50s
CI / Test (Node 22) (pull_request) Failing after 11m58s
CI / Test (Node 20) (pull_request) Failing after 12m1s
CI / Test (Node 18) (pull_request) Failing after 12m3s
2026-11-16 01:52:56 +00:00
Compare
jaylouisw deleted branch fix/1116-0136 2026-11-16 01:53:17 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1581
No description provided.