golib/database/csvx/null.go
AJ ONeal 59fae2e7ae
fix(csvx): read human null words as absent, unrecognized values as false
BoolishTimestamp defaulted unrecognized non-empty values to true: any
word it does not understand (a misspelling, "disabled", "banana")
behaved as on. Unrecognized values are now valid+false with the error
retained so callers can apply their own policy, and "disabled"/"disable"
are no longer true-like.

Both bool types now read the human "not supplied" set through one shared
isBoolNull sentinel: empty/whitespace-only, the exact PG dump sentinel
\N (case-sensitive), and the case-insensitive words null, \null, none,
unknown. Bool previously reached absent only by ParseBool failing; it
now matches BoolishTimestamp explicitly. Free-text types must not reuse
this set: most of these words are legitimate values there.
2026-10-23 23:00:57 -06:00

23 lines
645 B
Go

package csvx
import "strings"
// isBoolNull reports whether a human-edited cell means "not supplied":
// empty/whitespace-only, the exact PG dump sentinel `\N` (case-sensitive),
// or a case-insensitive match of null, \null, none, or unknown.
//
// Bool and BoolishTimestamp read such cells as absent. Free-text types
// must not reuse this set wholesale: most of these words are legitimate
// text values in non-boolean contexts.
func isBoolNull(raw string) bool {
s := strings.TrimSpace(raw)
if s == "" || s == `\N` {
return true
}
switch strings.ToLower(s) {
case "null", `\null`, "none", "unknown":
return true
}
return false
}