Skip to content

Commit

Permalink
fix(server): make the default value of number field clearable
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya committed Oct 29, 2024
1 parent 859fc79 commit 70085ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/pkg/value/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type propertyNumber struct{}
type Number = float64

func (p *propertyNumber) ToValue(i any) (any, bool) {
if i == "" {
return nil, true
}
switch v := i.(type) {
case float64:
return Number(v), true
Expand Down
6 changes: 6 additions & 0 deletions server/pkg/value/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func Test_propertyNumber_ToValue(t *testing.T) {
want1: float64(now.Unix()),
want2: true,
},
{
name: "empty string",
args: []any{""},
want1: nil,
want2: true,
},
{
name: "nil",
args: []any{"foo", (*float64)(nil), (*string)(nil), (*int)(nil), (*json.Number)(nil), nil},
Expand Down

0 comments on commit 70085ad

Please sign in to comment.