You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
query: omitempty ignores IsZero on named scalar and collection types #202
Values documents that a type returning true from IsZero() bool is empty, but isEmptyValue returns from its kind switch before checking that method for named integers, strings, slices, and the other kinds in the switch. A custom sentinel value is therefore sent as a query parameter even when its type explicitly marks it empty.
Reproduced on current master, 854f39986c87d97512b6cc5c59ccee17a72b248e:
Expected from the documented IsZero rule: an empty query. I also reproduced this with a named string whose sentinel is "unset" and a named slice whose IsZero returns true for a sentinel element. Both sent the sentinel instead of omitting the field; a normal nonempty integer still encoded as expected.
This is separate from #198/#199, which concern traversal of embedded structs. It affects ordinary exported fields. #25 introduced the general IsZero contract, but the kind-specific early returns still bypass it here.
Validation before any source changes:
go test -race -cover ./... passes, with 100% statement coverage.
The standalone reproduction above still sends the sentinel on that unchanged baseline.
I can contribute a focused fix and regression tests. Before changing compatibility behavior, should IsZero add to the existing built-in emptiness rules, or take precedence over them? The former would preserve omission of ordinary zero values and additionally omit custom sentinel values; the latter would also let a custom type keep its underlying zero value when its method returns false.
Activity