Parse the prefix on the prefix pages before looking it up #81

Merged
clawbot merged 1 commits from issue-71-prefix-page-parse into next 2026-10-14 17:24:04 +02:00
Collaborator

Fixes #71.

/prefix/{prefix}/{len} and /api/v1/prefix/{prefix}/{len} passed the URL text to the database lookup as typed. A prefix that does not parse, such as foo/24, answered 500 and was logged as a server error; a valid prefix written in a form other than the one the tables store (2001:DB8:0:0::/32 for a stored 2001:db8::/32, 192.0.2.1/24 for 192.0.2.0/24) answered 404.

Both handlers now parse the prefix with net/netip, mask it and look up the text form it prints, which is the form the tables store since #48. A prefix that does not parse answers 400: the JSON endpoint gives the parse error as its message, the HTML page says "Invalid prefix".

Worth knowing: the prefix field of the JSON answer, and the prefix the HTML page shows, are now the stored form rather than what the URL said, so /api/v1/prefix/192.0.2.1/24 answers with "prefix": "192.0.2.0/24".

The new test drives both pages through the router against a real database.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/routewatch/issues/71. `/prefix/{prefix}/{len}` and `/api/v1/prefix/{prefix}/{len}` passed the URL text to the database lookup as typed. A prefix that does not parse, such as `foo/24`, answered 500 and was logged as a server error; a valid prefix written in a form other than the one the tables store (`2001:DB8:0:0::/32` for a stored `2001:db8::/32`, `192.0.2.1/24` for `192.0.2.0/24`) answered 404. Both handlers now parse the prefix with `net/netip`, mask it and look up the text form it prints, which is the form the tables store since https://git.eeqj.de/sneak/routewatch/issues/48. A prefix that does not parse answers 400: the JSON endpoint gives the parse error as its message, the HTML page says "Invalid prefix". Worth knowing: the `prefix` field of the JSON answer, and the prefix the HTML page shows, are now the stored form rather than what the URL said, so `/api/v1/prefix/192.0.2.1/24` answers with `"prefix": "192.0.2.0/24"`. The new test drives both pages through the router against a real database. Model: opus-5-5
clawbot added the needs-review label 2026-10-14 16:11:22 +02:00
clawbot self-assigned this 2026-10-14 16:11:22 +02:00
clawbot added 1 commit 2026-10-14 16:11:22 +02:00
Both prefix pages passed the URL text to the lookup as typed. A prefix
that does not parse made the lookup fail with an error that was not "no
route found", so the pages answered 500; a valid prefix written in any
form other than the one the tables store answered 404 although the
route exists. Both handlers now parse the prefix with net/netip, mask
it and look up the text form it prints, and answer 400 for a prefix
that does not parse.

Model: opus-5-5
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 616f13071f into next 2026-10-14 17:24:03 +02:00
clawbot deleted branch issue-71-prefix-page-parse 2026-10-14 17:24:04 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/routewatch#81