mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-05-19 14:21:28 -04:00
backported some of the v0.23.0 form validators, fixes and tests
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user