fix(restheadspec): honour string URL ids on POST updates

POST with a non-numeric URL id (e.g. a string primary key) was treated as
having no id, so the body primary key was used to look up the existing row.
That broke primary key changes. Treat any non-empty, non-zero URL id as the
update target, and add an integration test through Handle for POST and PUT.
This commit is contained in:
Hein
2026-10-01 10:23:23 +02:00
parent 3bd3e46409
commit daeea241af
2 changed files with 32 additions and 2 deletions
+4 -2
View File
@@ -241,9 +241,11 @@ func (h *Handler) Handle(w common.ResponseWriter, r common.Request, params map[s
h.sendError(w, http.StatusBadRequest, "invalid_request", "Invalid request body", err)
return
}
validId, _ := strconv.ParseInt(id, 10, 64)
// A URL id is valid when it is a positive integer or any non-numeric
// string (string primary keys); "", "0" and negatives mean no id.
validId, parseErr := strconv.ParseInt(id, 10, 64)
updateID := id
isUpdate := validId > 0
isUpdate := id != "" && (parseErr != nil || validId > 0)
if !isUpdate {
// No valid /:id in the URL - check whether the body itself carries
// a valid primary key value and treat this as an update if so.