@@ -75,6 +75,13 @@ func (d *decoder) parseMapData() {
75
75
log .Panicf (errMissingStartBracket , k )
76
76
}
77
77
78
+ insideBracket = false
79
+
80
+ // ignore empty key
81
+ if i == idx + 1 {
82
+ continue
83
+ }
84
+
78
85
if rd = d .findAlias (k [:idx ]); rd == nil {
79
86
80
87
l = len (d .dm ) + 1
@@ -122,8 +129,6 @@ func (d *decoder) parseMapData() {
122
129
}
123
130
124
131
rd .keys = append (rd .keys , ke )
125
-
126
- insideBracket = false
127
132
default :
128
133
// checking if not a number, 0-9 is 48-57 in byte, see for yourself fmt.Println('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
129
134
if insideBracket && (k [i ] > 57 || k [i ] < 48 ) {
@@ -356,16 +361,24 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
356
361
d .parseMapData ()
357
362
// slice elements could be mixed eg. number and non-numbers Value[0]=[]string{"10"} and Value=[]string{"10","20"}
358
363
359
- if ok && len (arr ) > 0 {
360
- var varr reflect.Value
364
+ // handle also param[]=1¶m[]=2 syntax
365
+ arraySuffix := []byte ("[]" )
366
+ suffixNamespace := append (namespace , arraySuffix ... )
361
367
362
- var ol int
368
+ for _ , namespace := range [][]byte {namespace , suffixNamespace } {
369
+ arr , ok := d .values [string (namespace )]
363
370
l := len (arr )
364
371
372
+ if ! ok || l == 0 {
373
+ continue
374
+ }
375
+
376
+ var varr reflect.Value
377
+ var ol int
378
+
365
379
if v .IsNil () {
366
- varr = reflect .MakeSlice (v .Type (), len ( arr ), len ( arr ) )
380
+ varr = reflect .MakeSlice (v .Type (), l , l )
367
381
} else {
368
-
369
382
ol = v .Len ()
370
383
l += ol
371
384
@@ -456,14 +469,25 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
456
469
457
470
case reflect .Array :
458
471
d .parseMapData ()
459
-
460
472
// array elements could be mixed eg. number and non-numbers Value[0]=[]string{"10"} and Value=[]string{"10","20"}
461
473
462
- if ok && len (arr ) > 0 {
463
- var varr reflect.Value
474
+ // handle also param[]=1¶m[]=2 syntax
475
+ arraySuffix := []byte ("[]" )
476
+ suffixNamespace := append (namespace , arraySuffix ... )
477
+
478
+ var ol int
479
+
480
+ for _ , namespace := range [][]byte {namespace , suffixNamespace } {
481
+ arr , ok := d .values [string (namespace )]
464
482
l := len (arr )
465
- overCapacity := v .Len () < l
466
- if overCapacity {
483
+
484
+ if ! ok || l == 0 {
485
+ continue
486
+ }
487
+
488
+ var varr reflect.Value
489
+
490
+ if v .Len () < l {
467
491
// more values than array capacity, ignore values over capacity as it's possible some would just want
468
492
// to grab the first x number of elements; in the future strict mode logic should return an error
469
493
fmt .Println ("warning number of post form array values is larger than array capacity, ignoring overflow values" )
@@ -474,15 +498,19 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
474
498
if v .Len () < len (arr ) {
475
499
l = v .Len ()
476
500
}
477
- for i := 0 ; i < l ; i ++ {
501
+ l += ol
502
+
503
+ for i := ol ; i < l ; i ++ {
478
504
newVal := reflect .New (v .Type ().Elem ()).Elem ()
479
505
480
- if d .setFieldByType (newVal , namespace , i ) {
506
+ if d .setFieldByType (newVal , namespace , i - ol ) {
481
507
set = true
482
508
varr .Index (i ).Set (newVal )
483
509
}
484
510
}
511
+
485
512
v .Set (varr )
513
+ ol = l
486
514
}
487
515
488
516
// maybe it's an numbered array i.e. Phone[0].Number
0 commit comments