Description
While for most apps loose decoding is acceptable (and may be even preferable for speed), some require strict checking of form params (for ex. OAuth2 spec require this), and some other may like to enable it to make it easier to catch some bugs (like sending param with typo in name which now gets ignored by default and such bug may not be noticed for some time).
Returning new errors triggered by strict mode will require minor API changes:
- Decode() should return new error type(s) in addition to InvalidDecoderError and DecodeErrors
- probably Mode should be changed to use
1<<iota>>1
and have few more values added, which can be ORed with existing values to (partially) enable strict mode
Here is complete (I hope) list of changes required for strict mode:
- error on unknown param (related to Support DisallowUnknownKeys option #27)
- including param matching real, but not qualified enough field name:
- struct without .field (in case custom handler not registered)
- map without [key]
- array with out-of-bound [index]
- too many params for array field
- error instead of panic on field name with unmatched brackets (related to Decode shouldn't panic #7)
- including param matching real, but not qualified enough field name:
- error on decoding multiple values to same scalar
- multiple values for non-slice/array field Update: (except
[]byte
)- also pointer to slice/array (if such types are supported)
- Update: including multiple values for same
array[index]
ormap[key]
, in case this array/map doesn't have values of slice/array type
- multiple values for non-slice/array field Update: (except
- error on decoding no values to non-pointer/slice/array field tagged ",required"
I'm going to implement (at least, partially) this for my service, but implementing in a separate package will not be effective (because I'll have to duplicate existing functionality of form to reflect data structure, check field types and tags) and probably will be incomplete (not sure I can detect registered custom handlers for whole struct).
If you like the idea and open to discussing related PR then I'll try to implement this inside form and send a PR.