Currently the Go driver BSON decoder will decode many types, including BSON booleans, into Go booleans. The current rules are:
- BSON boolean - Match the BSON boolean value.
- BSON int32 - Any non-zero value is Go true.
- BSON int64 - Any non-zero value is Go true.
- BSON double - Any non-zero value is Go true.
- BSON null - Always Go false.
- BSON undefined - Always Go false.
Check out an example here.
However, other drivers for statically typed languages (e.g. Rust) only allow strict BSON boolean -> native boolean decoding. Update the Go behavior to default to strict BSON boolean -> Go boolean decoding. Add a decoder option that enables "strict" decoding that prevents implicit type conversion.
Open questions:
- Should we keep the existing behavior as the default and add a configuration option that only allows strict value type assignment? Or should we update the default to be strict?
- Should we also disallow implicit type conversion for numeric types?
- What motivated this?
Definition of done:
- Add an option to bson.Decoder that requires "strict" BSON -> Go type decoding behavior.
- What types should this apply to? Boolean only? Integer and float also?