From 3508a83307a9b3fb6c93db81482706dbbaea92cc Mon Sep 17 00:00:00 2001 From: xarmian Date: Wed, 13 May 2026 04:11:34 +0000 Subject: [PATCH] fix(cli): reject NaN/Inf in --field number parsing per Codex review (round 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strconv.ParseFloat accepts "NaN", "+Inf", "-Inf" as valid float64 values, but encoding/json cannot marshal those. The downstream json.Marshal(fields) errors at cmd/pad/main.go createCmd / updateCmd are intentionally ignored (`fieldsJSON, _ := json.Marshal(fields)`), so a single malformed --field input would silently drop the entire fields payload instead of rejecting. Reject non-finite floats in parseFieldFlag and fall back to the raw string; the server validator then returns the useful "field X must be a number" error. Verified: pad item update BLOG-1393 --field reading_time=NaN → "must be a number" ✓ pad item update BLOG-1393 --field reading_time=Inf → "must be a number" ✓ pad item update BLOG-1393 --field reading_time=4 → stored as 4 ✓ --- cmd/pad/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/pad/main.go b/cmd/pad/main.go index 0763d7ea..a27777f9 100644 --- a/cmd/pad/main.go +++ b/cmd/pad/main.go @@ -10,6 +10,7 @@ import ( "io" "io/fs" "log/slog" + "math" goMime "mime" "net/http" "net/url" @@ -2821,7 +2822,14 @@ func parseFieldFlag(schema models.CollectionSchema, key, raw string) any { } case "number": if f, err := strconv.ParseFloat(raw, 64); err == nil { - return f + // Reject NaN / ±Inf — encoding/json can't marshal them, and + // the downstream json.Marshal(fields) error is ignored, so + // returning a non-finite float would silently drop the entire + // fields payload. Falling back to the raw string lets the + // server validator return a useful "must be a number" error. + if !math.IsNaN(f) && !math.IsInf(f, 0) { + return f + } } case "checkbox": if b, err := strconv.ParseBool(raw); err == nil {