@@ -121,16 +121,11 @@ func (d *Decoder) Decode(v interface{}, values url.Values) (err error) {
121121 val := reflect .ValueOf (v )
122122
123123 if val .Kind () == reflect .Ptr {
124-
125- if val .IsNil () && val .CanSet () {
126- val .Set (reflect .New (val .Type ().Elem ()))
127- }
128-
129124 val = val .Elem ()
130125 }
131126
132- if val .Kind () != reflect .Struct && val . Kind () != reflect . Interface {
133- panic ("value passed for validation is not a struct" )
127+ if val .Kind () != reflect .Struct {
128+ panic ("interface must be a pointer to a struct" )
134129 }
135130
136131 dec .traverseStruct (val , "" )
@@ -297,18 +292,13 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
297292 return
298293 }
299294 }
300- return
301295 }
302296
303297 switch kind {
304298 case reflect .Interface , reflect .Invalid :
305299 return
306300 case reflect .Ptr :
307301
308- if ! ok {
309- return
310- }
311-
312302 newVal := reflect .New (v .Type ().Elem ())
313303 if set = d .setFieldByType (newVal .Elem (), namespace , idx ); set {
314304 v .Set (newVal )
@@ -332,7 +322,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
332322 var u64 uint64
333323
334324 if u64 , err = strconv .ParseUint (arr [idx ], 10 , 64 ); err != nil || v .OverflowUint (u64 ) {
335- d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s', Type '%v'" , arr [idx ], v .Type ()))
325+ d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s' " , arr [idx ], v .Type (), namespace ))
336326 return
337327 }
338328
@@ -346,7 +336,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
346336 var i64 int64
347337
348338 if i64 , err = strconv .ParseInt (arr [idx ], 10 , 64 ); err != nil || v .OverflowInt (i64 ) {
349- d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s', Type '%v'" , arr [idx ], v .Type ()))
339+ d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s' " , arr [idx ], v .Type (), namespace ))
350340 return
351341 }
352342
@@ -362,7 +352,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
362352 var f float64
363353
364354 if f , err = strconv .ParseFloat (arr [idx ], 64 ); err != nil || v .OverflowFloat (f ) {
365- d .setError (namespace , fmt .Errorf ("Invalid Float Value '%s', Type '%v'" , arr [0 ], v .Type ()))
355+ d .setError (namespace , fmt .Errorf ("Invalid Float Value '%s' Type '%v' Namespace '%s' " , arr [0 ], v .Type (), namespace ))
366356 return
367357 }
368358
@@ -378,7 +368,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
378368 var b bool
379369
380370 if b , err = strconv .ParseBool (arr [idx ]); err != nil {
381- d .setError (namespace , fmt .Errorf ("Invalid Boolean Value '%s', Type '%v'" , arr [idx ], v .Type ()))
371+ d .setError (namespace , fmt .Errorf ("Invalid Boolean Value '%s' Type '%v' Namespace '%s' " , arr [idx ], v .Type (), namespace ))
382372 return
383373 }
384374
@@ -484,7 +474,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
484474 newVal := reflect .New (typ .Elem ()).Elem ()
485475 kv := reflect .New (typ .Key ()).Elem ()
486476
487- if err := d .getMapKey (rd .keys [i ].value , kv ); err != nil {
477+ if err := d .getMapKey (rd .keys [i ].value , kv , namespace ); err != nil {
488478 d .setError (namespace , err )
489479 continue
490480 }
@@ -506,7 +496,11 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
506496 // if we get here then no custom time function declared so use RFC3339 by default
507497 if v .Type () == timeType {
508498
509- t , err := time .Parse (time .RFC3339 , arr [0 ])
499+ if ! ok || len (arr [idx ]) == 0 {
500+ return
501+ }
502+
503+ t , err := time .Parse (time .RFC3339 , arr [idx ])
510504 if err != nil {
511505 d .setError (namespace , err )
512506 }
@@ -521,7 +515,7 @@ func (d *formDecoder) setFieldByType(current reflect.Value, namespace string, id
521515 return
522516}
523517
524- func (d * formDecoder ) getMapKey (key string , current reflect.Value ) (err error ) {
518+ func (d * formDecoder ) getMapKey (key string , current reflect.Value , namespace string ) (err error ) {
525519
526520 v , kind := d .d .ExtractType (current )
527521
@@ -531,7 +525,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
531525 case reflect .Ptr :
532526
533527 newVal := reflect .New (v .Type ().Elem ())
534- if err = d .getMapKey (key , newVal .Elem ()); err == nil {
528+ if err = d .getMapKey (key , newVal .Elem (), namespace ); err == nil {
535529 v .Set (newVal )
536530 }
537531
@@ -542,7 +536,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
542536
543537 u64 , e := strconv .ParseUint (key , 10 , 64 )
544538 if e != nil || v .OverflowUint (u64 ) {
545- err = fmt .Errorf ("Invalid Unsigned Integer Value '%s', Type '%v'" , key , v .Type ())
539+ err = fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s' " , key , v .Type (), namespace )
546540 return
547541 }
548542
@@ -552,7 +546,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
552546
553547 i64 , e := strconv .ParseInt (key , 10 , 64 )
554548 if e != nil || v .OverflowInt (i64 ) {
555- err = fmt .Errorf ("Invalid Integer Value '%s', Type '%v'" , key , v .Type ())
549+ err = fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s' " , key , v .Type (), namespace )
556550 return
557551 }
558552
@@ -562,7 +556,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
562556
563557 f , e := strconv .ParseFloat (key , 64 )
564558 if e != nil || v .OverflowFloat (f ) {
565- err = fmt .Errorf ("Invalid Float Value '%s', Type '%v'" , key , v .Type ())
559+ err = fmt .Errorf ("Invalid Float Value '%s' Type '%v' Namespace '%s' " , key , v .Type (), namespace )
566560 return
567561 }
568562
@@ -572,7 +566,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
572566
573567 b , e := strconv .ParseBool (key )
574568 if e != nil {
575- err = fmt .Errorf ("Invalid Boolean Value '%s', Type '%v'" , key , v .Type ())
569+ err = fmt .Errorf ("Invalid Boolean Value '%s' Type '%v' Namespace '%s' " , key , v .Type (), namespace )
576570 return
577571 }
578572
@@ -581,7 +575,7 @@ func (d *formDecoder) getMapKey(key string, current reflect.Value) (err error) {
581575 default :
582576 // look for custom type? or should it be done before this switch, must check out bson.ObjectId because is of typee
583577 // string but requires a specific method to ensure that it's valid
584- err = fmt .Errorf ("Unsupported Map Key '%s', Type '%v'" , key , v .Type ())
578+ err = fmt .Errorf ("Unsupported Map Key '%s', Type '%v' Namespace '%s' " , key , v .Type (), namespace )
585579 }
586580
587581 return
0 commit comments