From c530a7f61841fcc53364a26c2ec66ad1fa024eed Mon Sep 17 00:00:00 2001 From: Vitaliy <160263432+vitalivo@users.noreply.github.com> Date: Sat, 12 Sep 2026 16:24:57 +0300 Subject: [PATCH] Validate unsigned integer strings across the uint64 range --- internal/validators/type_check.go | 2 +- validators_test.go | 14 ++++++++++++++ validators_type.go | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/validators/type_check.go b/internal/validators/type_check.go index 44c4b29..47464e3 100644 --- a/internal/validators/type_check.go +++ b/internal/validators/type_check.go @@ -36,7 +36,7 @@ func IsUint(fl *fieldval.FieldValue) bool { case uint, uint8, uint16, uint32, uint64: return true case string: - _, err := strconv.ParseUint(typVal, 10, 32) + _, err := strconv.ParseUint(typVal, 10, 64) return err == nil } return false diff --git a/validators_test.go b/validators_test.go index ff6a427..a616fa2 100644 --- a/validators_test.go +++ b/validators_test.go @@ -758,3 +758,17 @@ func TestDateCheck(t *testing.T) { is.False(AfterOrEqualDate("invalid", "2018-10-26")) is.False(AfterOrEqualDate("2018-10-25", "invalid")) } + +func TestIsUintFullRange(t *testing.T) { + for _, value := range []string{"4294967295", "4294967296", "18446744073709551615"} { + t.Run(value, func(t *testing.T) { + assert.True(t, IsUint(value)) + v := Map(map[string]any{"number": value}) + v.StringRule("number", "uint") + assert.True(t, v.Validate()) + }) + } + for _, value := range []string{"-1", "18446744073709551616", "1.5", ""} { + assert.False(t, IsUint(value)) + } +} diff --git a/validators_type.go b/validators_type.go index d58f009..e5ca3d1 100644 --- a/validators_type.go +++ b/validators_type.go @@ -30,7 +30,7 @@ func IsUint(val any) bool { case uint, uint8, uint16, uint32, uint64: return true case string: - _, err := strconv.ParseUint(typVal, 10, 32) + _, err := strconv.ParseUint(typVal, 10, 64) return err == nil } return false