backported some of the v0.23.0 form validators, fixes and tests

This commit is contained in:
Gani Georgiev
2024-10-18 16:03:49 +03:00
parent e92d3cccd0
commit cbc88d7a01
5 changed files with 100 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ package validators
import (
"fmt"
"math"
"net/url"
"regexp"
"strings"
@@ -159,6 +160,10 @@ func (validator *RecordDataValidator) checkNumberValue(field *schema.SchemaField
return nil // nothing to check (skip zero-defaults)
}
if math.IsInf(val, 0) || math.IsNaN(val) {
return validation.NewError("validation_nan", "The submitted number is not properly formatted")
}
options, _ := field.Options.(*schema.NumberOptions)
if options.NoDecimal && val != float64(int64(val)) {

View File

@@ -248,6 +248,16 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
nil,
[]string{"field2"},
},
{
"(number) check infinities and NaN",
map[string]any{
"field1": "Inf",
"field2": "-Inf",
"field4": "NaN",
},
nil,
[]string{"field1", "field2", "field4"},
},
{
"(number) check min constraint",
map[string]any{