1
0
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:
Gani Georgiev 2024-10-18 17:38:19 +03:00
parent ae86525c13
commit be908ad4bf
2 changed files with 25 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {