Skip to content

Commit 298ec05

Browse files
committed
fix: safe to process array type
1 parent 93d6fe5 commit 298ec05

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717

1818
require (
1919
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
20-
github.com/go-json-experiment/json v0.0.0-20250625182306-a9cfae7f3654
20+
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b
2121
github.com/juju/ansiterm v1.0.0
2222
github.com/onsi/gomega v1.37.0
2323
golang.org/x/net v0.41.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 h1:o8UqXPI
88
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
99
github.com/go-json-experiment/json v0.0.0-20250625182306-a9cfae7f3654 h1:oSbYHc9OIFoLuGxc6oxRnEmv19baVLVEPfucUdXb/4A=
1010
github.com/go-json-experiment/json v0.0.0-20250625182306-a9cfae7f3654/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
11+
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b h1:ooF9/NzXkXL3OOLRwtPuQT/D7Kx2S5w/Kl1GnMF9h2s=
12+
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
1113
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
1214
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
1315
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=

pkg/validator/internal/validator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func (v *validators) defaultRule(t reflect.Type) string {
211211
return "@double"
212212
case reflect.String:
213213
return "@string"
214+
default:
214215
}
215216
}
216217

pkg/validator/internal/value.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ type Array struct {
579579
Validator Validator
580580
}
581581

582+
func (va *Array) SetLen(n int) {
583+
if va.Kind() == reflect.Slice {
584+
va.Value.SetLen(n)
585+
}
586+
}
587+
582588
func (va *Array) UnmarshalDecode(dec *jsontext.Decoder, options json.Options) error {
583589
tok, err := dec.ReadToken()
584590
if err != nil {

pkg/validator/validators/slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (validator *SliceValidator) String() string {
111111

112112
func (validator *SliceValidator) PostValidate(rv reflect.Value) error {
113113
lenOfValue := uint64(0)
114-
if !rv.IsNil() {
114+
if rv.Kind() == reflect.Array || !rv.IsNil() {
115115
lenOfValue = uint64(rv.Len())
116116
}
117117

0 commit comments

Comments
 (0)