Serve the index page for an empty URL path instead of panicking (closes #149) #165

Merged
clawbot merged 1 commits from issue-149-spa-empty-path into next 2026-10-20 21:31:26 +02:00
Collaborator

setupSPA in internal/server/routes.go took the file name from request.URL.Path[1:], which panics when the path is empty. An absolute-form request line with no path (GET http://host HTTP/1.1) gives an empty path, so any client could make the server answer 500 and log a stack trace. It now uses strings.TrimPrefix(request.URL.Path, "/"). An empty name fails to read from the embedded files, so the request gets the index page through the fallback that already serves GET / and unknown paths.

internal/server/routes_test.go sends such a request and expects 200 and the index page. The package had no tests before; internal/server/export_test.go gives the test a Server whose router has only the web client route, following the export_test.go files in internal/ircserver and internal/db.

Closes #149

  • Judgement call: the test builds its request with httptest.NewRequestWithContext(t.Context(), ...) rather than httptest.NewRequest; the request and its empty path are the same.
  • Partially verified: in the Docker test build web/dist/index.html is an empty placeholder, so there the body check compares empty with empty; the status and the absence of a panic carry the test.

Model: opus-5-5

`setupSPA` in `internal/server/routes.go` took the file name from `request.URL.Path[1:]`, which panics when the path is empty. An absolute-form request line with no path (`GET http://host HTTP/1.1`) gives an empty path, so any client could make the server answer `500` and log a stack trace. It now uses `strings.TrimPrefix(request.URL.Path, "/")`. An empty name fails to read from the embedded files, so the request gets the index page through the fallback that already serves `GET /` and unknown paths. `internal/server/routes_test.go` sends such a request and expects `200` and the index page. The package had no tests before; `internal/server/export_test.go` gives the test a `Server` whose router has only the web client route, following the `export_test.go` files in `internal/ircserver` and `internal/db`. Closes https://git.eeqj.de/sneak/neoirc/issues/149 - Judgement call: the test builds its request with `httptest.NewRequestWithContext(t.Context(), ...)` rather than `httptest.NewRequest`; the request and its empty path are the same. - Partially verified: in the Docker test build `web/dist/index.html` is an empty placeholder, so there the body check compares empty with empty; the status and the absence of a panic carry the test. Model: opus-5-5
clawbot added the needs-review label 2026-10-20 21:03:14 +02:00
clawbot self-assigned this 2026-10-20 21:03:14 +02:00
clawbot added 1 commit 2026-10-20 21:03:15 +02:00
setupSPA took the file name from request.URL.Path[1:], which panics
when the path is empty, as it is for an absolute-form request line
with no path ("GET http://host HTTP/1.1"). It now trims a leading "/"
instead; an empty name fails to read, so the request gets the index
page, as "/" already does.

The new test in internal/server sends such a request and expects 200
and the index page. export_test.go gives it a Server whose router has
only the web client route.

Model: opus-5-5
Author
Collaborator

PASS

Model: opus-5-5

**PASS** Model: opus-5-5
clawbot removed the needs-review label 2026-10-20 21:28:50 +02:00
clawbot merged commit 292f1eb7a9 into next 2026-10-20 21:31:26 +02:00
clawbot deleted branch issue-149-spa-empty-path 2026-10-20 21:31:26 +02:00
Sign in to join this conversation.