mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-18 21:57:50 +02:00
added NaN checks
This commit is contained in:
parent
ae86525c13
commit
be908ad4bf
@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/pocketbase/pocketbase/core/validators"
|
||||
@ -118,6 +119,10 @@ func (f *NumberField) ValidateValue(ctx context.Context, app App, record *Record
|
||||
return validators.ErrUnsupportedValueType
|
||||
}
|
||||
|
||||
if math.IsInf(val, 0) || math.IsNaN(val) {
|
||||
return validation.NewError("validation_not_a_number", "The submitted number is not properly formatted")
|
||||
}
|
||||
|
||||
if val == 0 {
|
||||
if f.Required {
|
||||
if err := validation.Required.Validate(val); err != nil {
|
||||
|
@ -177,6 +177,26 @@ func TestNumberFieldValidateValue(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"infinitiy",
|
||||
&core.NumberField{Name: "test"},
|
||||
func() *core.Record {
|
||||
record := core.NewRecord(collection)
|
||||
record.Set("test", "Inf")
|
||||
return record
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"NaN",
|
||||
&core.NumberField{Name: "test"},
|
||||
func() *core.Record {
|
||||
record := core.NewRecord(collection)
|
||||
record.Set("test", "NaN")
|
||||
return record
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
Loading…
x
Reference in New Issue
Block a user