parseUUIDOrBadRequest validates a UUID string sourced from user input (URL params, request body, headers). On invalid input it writes a 400 response and returns ok=false; callers must return immediately. Use this anywhere a malformed UUID would otherwise reach a write query (DELETE / UPDATE) — the
(w http.ResponseWriter, s, fieldName string)
| 315 | // (DELETE / UPDATE) — the silent zero-UUID behavior of the old ParseUUID |
| 316 | // caused real silent-data-loss bugs (#1661). |
| 317 | func parseUUIDOrBadRequest(w http.ResponseWriter, s, fieldName string) (pgtype.UUID, bool) { |
| 318 | u, err := util.ParseUUID(s) |
| 319 | if err != nil { |
| 320 | writeError(w, http.StatusBadRequest, "invalid "+fieldName) |
| 321 | return pgtype.UUID{}, false |
| 322 | } |
| 323 | return u, true |
| 324 | } |
| 325 | |
| 326 | func parseUUIDSliceOrBadRequest(w http.ResponseWriter, ids []string, fieldName string) ([]pgtype.UUID, bool) { |
| 327 | uuids := make([]pgtype.UUID, len(ids)) |
no test coverage detected